Good job! Now, let's introduce some time constraints to our revenue reports. Take a look:
SUM(Amount) AS TotalRevenue
FROM Orders O
JOIN Customers C
ON O.CustomerId = C.CustomerId
WHERE O.OrderDate >= '20170301' AND O.OrderDate < '20170401'
GROUP BY C.CustomerId, CompanyName;
The query above shows total revenue per customer, but this time it's based on orders from March 2017. We've added a
WHERE clause, inside which we defined the range for
OrderDate. Note the date format that we used:
YYYYMMDD. In other words,
O.OrderDate >= '20170301' means 'orders placed on March 1, 2017 or later'. Note that the month comes before the day in this date format – this might be counterintuitive for people from the US. The other condition that we used is
O.OrderDate < '20170401', which means "orders placed before April 1, 2017".