时间:2021-07-01 10:21:17 帮助过:2人阅读
SELECT s_Age ,COUNT(s_ID)FROM dbo.Student GROUP BY s_Name--错误,Group By后面的列,必须要在select子句中列的列表中出现。
--对分组之后的年龄,分组,HAVING COUNT(s_Age) =1
SELECT s_Age ,COUNT(s_ID)FROM dbo.Student GROUP BY s_Age HAVING COUNT(s_Age) =1
下面这个SQL,执行报错:HAVING 子句中的列 ‘dbo.Student.s_Name‘ 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
SELECT s_Age ,COUNT(s_ID)FROM dbo.Student GROUP BY s_Age HAVING s_Name IS NOT NULL
SQL--Having
标签: