嘿,我是SQL新手,以下内容不起作用。 基本上语法是正确的
SELECT Hometeam, count(*)
FROM [dbo].[E0$]
GROUP BY Hometeam
HAVING COUNT(*) >3
但是当我计算结果时,它会失败。
SELECT count(*)
FROM (SELECT Hometeam, count(*)
FROM [dbo].[E0$]
GROUP BY Hometeam
HAVING COUNT(*) >3)
Msg 102,Level 15,State 1,Line 75 ')'附近的语法不正确。
答案 0 :(得分:1)
子查询本身及其中的列都需要别名。
SELECT count(*)
FROM (
SELECT Hometeam, count(*) as cnt
FROM [dbo].[E0$]
GROUP BY Hometeam
HAVING COUNT(*) >3
) x
答案 1 :(得分:-1)
你必须把一些东西放在Count方法中。
https://technet.microsoft.com/en-us/library/ms175997(v=sql.110).aspx
例如:
Select count(1)...