1. Learn
  2. /
  3. Courses
  4. /
  5. Hierarchical and Recursive Queries in SQL Server

Exercise

Getting the number of orders & total costs

In this exercise, you will JOIN two tables to get the total number of orders for each person and the sum of prices of all orders. You have to join the Person and History tables on the primary and foreign keys to get all required information.

Instructions

100 XP
  • COUNT() the number of orders and alias it as Orders.
  • SUM() the total price of all orders and alias it as Costs.
  • Join the Person and History tables.
  • Aggregate the information on ID using GROUP BY.