I have three tables in sql
order_table (order_id, product_id, amount)
products_table (product_id, name, price_usd),
all_orders (order_id, customer_id, order_date, total_amount),
I want to generate a SQL query that outputs the total revenue for each product by month for the past 12 months.
I somehow need to separate out the different products, but I'm not sure how to structure a query like this.
Any pointers would be great
The
answer given is to use WITH....
Should do the same thing (untested), which is not needed: