select
product_id,product_name,
sum(coalesce(total_amount,0)) q2_2024_sales_total,
rank() OVER(PARTITION BY category order by COALESCE(sum(total_amount),0) desc) category_rank,
supplier_name
FROM
product_info s1
left JOIN
(select * FROM order_info where date_format(order_date,'%y%m') between 2404 and 2406) s2
using(product_id)
left JOIN
supplier_info s3
using(product_id)
group by 1,2,category,5
order by 1



京公网安备 11010502036488号