Select and Group by together

后端 未结 2 815
有刺的猬
有刺的猬 2021-01-19 00:47

I have my query like this:

Select 
  a.abc,
  a.cde,
  a.efg,
  a.agh,
  c.dummy
  p.test
  max(b.this)
  sum(b.sugar)
  sum(b.bucket)
  sum(b.something)
         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 01:14

    SQL will insist that any column in the SELECT section is either included in the GROUP BY section or has an aggregate function applied to it in the SELECT section.

    This article gives a nice explanation of why this is the case. The article is sql server specific but the principle should be roughly similar for all RDBMS

提交回复
热议问题