with t1 as 
(select products.product_id,product_name ,sum(sales_amount) total_sales_amount,sum(sales_quantity) total_sales_quantity,rank()over( order by sum(sales_quantity) desc) rk
from products join sales_records on products.product_id=sales_records.product_id
where sales_date between '2024-01-01' and '2024-12-31'
group by products.product_id
order by total_sales_quantity desc,products.product_id)

select product_id,product_name,total_sales_amount,total_sales_quantity
from t1
where rk=1
order by product_id