Calculate the Quarterly Revenue
Consider two tables:
Orders table has columns:
quantity (int), and
Products table has columns:
name (varchar), and
Write a SQL query to calculate the total revenue (quantity times price) for each quarter of a year.
DB Fiddle Instructions
Click ‘Edit on DB Fiddle’ to be taken to the in browser SQL playground where you can run your queries.
First, we create a CTE
QuarterlyOrders to calculate the total quantity ordered for each product in each quarter. In the main query, we join this CTE with the
Products table and calculate the total revenue (total quantity times price) for each quarter.