2009-07-09 74 views
25

當我運行查詢:SQL Server的子查詢語法

select count(*) from 
(select idCover from x90..dimCover group by idCover having count(*) > 1) 

我得到的錯誤:

Server: Msg 170, Level 15, State 1, Line 2 
Line 2: Incorrect syntax near ')' 

如何正確制定此查詢?

我的SQL Server 2000

回答

38

你的最後括號後面添加一個別名。

select count(*) from 
(select idCover from x90..dimCover group by idCover having count(*) > 1) a 
14
SELECT COUNT (*) FROM 
(SELECT IdCover FROM x90..dimCover group by idCover having count(*) > 1) AS a 

(注意最後的別名)