Select multiple columns from a table, but group by one

后端 未结 11 1444
逝去的感伤
逝去的感伤 2020-12-12 14:54

The table name is \"OrderDetails\" and columns are given below:

OrderDetailID || ProductID || ProductName || OrderQuantity

I\'m trying to s

11条回答
  •  甜味超标
    2020-12-12 15:22

    You can try this:

    Select ProductID,ProductName,Sum(OrderQuantity) 
     from OrderDetails Group By ProductID, ProductName
    

    You're only required to Group By columns that doesn't come with an aggregate function in the Select clause. So you can just use Group By ProductID and ProductName in this case.

提交回复
热议问题