sql server - SQL: Select Top 3 Records + Sum of Quantity -
i display top 3 records existing orders table. in order accomplish this, need calculate sum of each product's quantity.
existing records:
orderno productid quantity 1 1 50 1 2 30 1 3 20 2 2 30 3 1 100 3 4 50 4 1 20 4 5 10 5 2 10 expected output
productid quantity 1 170 2 70 4 50
you need sum , order by summary value:
select top 3 productid, sum(quantity) qsum table group productid order qsum desc
Comments
Post a Comment