Do all columns in a SELECT list have to appear in a GROUP BY clause

后端 未结 7 1215
悲&欢浪女
悲&欢浪女 2020-11-30 19:50

My lecturer stated:

All column names in SELECT list must appear in GROUP BY clause unless name is used only in an aggregate function

I\'m ju

7条回答
  •  自闭症患者
    2020-11-30 20:11

    There are exceptions as noted by Sam Saffron but generally what your lecturer said is true.

    If I select 3 columns and group by 2 what should the RDBMS do with the 3rd column?

    The developers of the RDBMS may make a decision of how to handle the extra colum (as it appears MySQL's developers have) but is it the decision I would have made or the one I want when writing the select? Will the decision always be valid? I certainly prefer the Oracle-like approach of forcing me to explicitly state what should happen.

    If I select 3 columns and group by 2 should the RDBS group by all 3, pick a random value from the 3rd, the biggest or littlest, the most common?

提交回复
热议问题