-- 逻辑拆解:连接表,按照商品分组,聚合求销售额,时间条件-2024年上半年(特别注意不能直接用where条件筛选时间,因为这样会变相把LEFT JOIN变成inner join) SELECT t1.product_id, t1.product_name, SUM(t1.price * t2.quantity) total_sales FROM products_underline t1 LEFT JOIN sales_underline t2 ON t1.product_id = t2.product_id AND t2.sale_month BETWEEN '2024-01' AND '2024-06' GROUP BY t1.product_id ORDER BY t1.product_id