select
    t.product_id,
    p.product_name,
    total_sales_amount,
    total_sales_quantity
from
    (
        select
            p.product_id,
            sum(sales_amount) as total_sales_amount,
            sum(sales_quantity) as total_sales_quantity,
            rank() over (
                order by
                    sum(sales_quantity) desc
            ) as rk
        from
            products p
            inner join sales_records sr on p.product_id = sr.product_id
        where
            sales_date between "2024-01-01" and "2024-12-31"
        group by
            p.product_id
    ) as t
    inner join products p on t.product_id = p.product_id
where
    rk = 1
order by
    t.product_id asc;