like i have 1000 order entry in each entry i have multiple products with sold quantity for top selling products.heaare my challange is i need return the top sold products example:

order entry  : product id  :sold quantity;;;;
entry 1     : productA    :20 
            :productB     :10
             :productC     :5
entry 2      :productB     :5
             :productc      :20

how can get the top selling product.

1

There are 1 best solutions below

3
On

If I understand correctly, this is aggregation with order by:

select product_id, sum(quantity) as total_quantity
from t
group by product_id
order by total_quantity desc
limit 10;