SQL: Select Top 3 Records + Sum of Quantity

后端 未结 2 1464
广开言路
广开言路 2020-12-18 06:39

I would like to display the top 3 records from the existing Orders table. In order to accomplish this, I need to calculate the sum of each product\'s quanti

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 06:48

    SELECT TOP 3 ProductID, SUM(Quantity) as SUMQUANTITY
    FROM Table1
    GROUP BY ProductID
    ORDER BY SUMQUANTITY desc
    

    SQL Fiddle Demo

提交回复
热议问题