Practice Aggregation
Explore SQL aggregation techniques by writing queries that count late deliveries per employee, group products by monthly sales performance, and calculate a 5-day moving average of order values per customer tier. Develop skills to analyze data using counting, categorizing, and cumulative metrics within SQL.
Aggregation patterns questions
Let’s practice writing queries to strengthen your grasp of aggregation patterns.
Count the late deliveries
Given the following structure of the Orders table:
Field | Type |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Where OrderID is the primary key and CustomerID is the foreign key from the Customers table referring to the customer who placed the order.
The table contains information about the orders placed. In the Orders table, each order is optionally assigned to an employee (EmployeeID) responsible for processing or managing the delivery. The table also includes a LateDelivery field, which is a boolean indicating whether the order was delivered later than expected.
Write an SQL query to find out how many late deliveries are associated with each employee. Only include: ...