Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果聚合(例如使用 SUM),是否需要按您选择的内容进行分组?你必须有一个group by子句?
不,这不是要求。
没有 aGROUP BY的聚合是标量聚合,并且总是只返回一行。
GROUP BY
例子
SELECT SUM(high) FROM master..spt_values WHERE 1 = 0
带有 a 的聚合GROUP BY是 Vector 聚合,每组返回零或一行。
SELECT [type], SUM(high) FROM master..spt_values WHERE 1 = 0 GROUP BY [type]