with t1 as ( select product_id, product_name, sum(sales_amount) as total_sales_amount, sum(sales_quantity) as total_sales_quantity, dense_rank() over ( order by sum(sales_quantity) desc ) as rk from sales_records join products using (product_id) where year(sales_date) = 2024 group by product_id, product_name ) select product_id, product_name, total_sales_amount, total_sales_quantity from t1 where rk = 1 order by product_id asc;