简体   繁体   中英

order entryes have multiple product with sold quantity how to get the top sold products based on how many products are sold

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM