select
DATE_FORMAT(all_orders.order_date, '%Y-%m') as order_date,
name as product_name,
sum(total_amount) as total_quantity,
sum(price_usd * total_amount) as total_revenue
from all_orders
LEFT JOIN order_table USING (order_id)
LEFT JOIN products_table USING (product_id)
where all_orders.order_date >= date_sub(current_date(), interval 12 month)
group by 1,2 ;
给出的答案是使用
WITH....
,这是不需要的:应该做同样的事情(未经测试)