QUARTER(order_date) = 2直接判断日期为第二季度,本题要理清运行顺序
分析每个商品在不同时间段的销售情况
https://www.nowcoder.com/practice/eec7a93e1ab24233bd244e04e910d2f9
select pi.product_id, pi.product_name, sum(ifnull(total_amount,0)) as q2_2024_sales_total # 解决空值问题, row_number()over ( partition by pi.category order by sum(total_amount) desc ) as category_rank, supplier_name from product_info as pi left join order_info as oi on pi.product_id = oi.product_id and QUARTER(order_date) = 2 # 判断为第二季度 left join supplier_info as si on si.product_id = pi.product_id # 连接到pi表解决 supplier_name为 none 问题 group by pi.product_id order by product_id asc