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....
,這是不需要的:應該做同樣的事情(未經測試)