2014-04-10 59 views
0

SQL子查詢我有以下查詢與計數錯誤

select Obj.regcode,count(*) 
FROM  dbo.Objecten Obj   
INNER JOIN dbo.Dossiers Dos ON obj.objectnr=Dos.objectnr 
WHERE Dos.plan_gereed between '2014-01-01' and '2014-02-01' 
group by obj.regcode having count(*) > 1 

做工精細,加起來,僅顯示有多個註冊碼的的人。

現在我想再次將它們分開,所以我可以查看哪些dossiernr與regcode結合在一起。 (我需要他們組第一之前,我可以決定哪些註冊碼被多次使用在限定的時間間隔)

,所以我想我的查詢會是這樣的:

SELECT obj.regcode, Dos.dossiernr 
FROM  dbo.objecten obj, 
     dbo.Dossiers Dos 
WHERE obj.regcode IN (select Obj.regcode,count(*) 
          FROM  dbo.Objecten Obj   
          INNER JOIN dbo.Dossiers Dos ON obj.objectnr=Dos.objectnr 
          WHERE Dos.plan_gereed between '2014-01-01' and '2014-02-01' 
          group by obj.regcode 
          having count(*) > 1) 
AND  obj.objectnr=Dos.objectnr 

但是這一次提供了以下錯誤:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

任何人都可以幫助我嗎?

在此先感謝

回答

0

剛剛從IN刪除COUNT(*)選擇入住

SELECT obj.regcode, Dos.dossiernr FROM dbo.objecten obj, dbo.Dossiers Dos WHERE obj.regcode IN (select Obj.regcode FROM dbo.Objecten Obj INNER JOIN dbo.Dossiers Dos ON obj.objectnr=Dos.objectnr WHERE 
Dos.plan_gereed between '2014-01-01' and '2014-02-01' group by obj.regcode having count(*) > 1) AND obj.objectnr=Dos.objectnr