Select multiple columns from a table, but group by one

后端 未结 11 1440
逝去的感伤
逝去的感伤 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:30

    ==EDIT==

    I checked your question again and have concluded this can't be done.

    ProductName is not unique, It must either be part of the Group By or excluded from your results.

    For example how would SQL present these results to you if you Group By only ProductID?

    ProductID | ProductName | OrderQuantity 
    ---------------------------------------
    1234      | abc         | 1
    1234      | def         | 1
    1234      | ghi         | 1
    1234      | jkl         | 1
    

提交回复
热议问题