An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING cla

Posted by brz dot net on Stack Overflow See other posts from Stack Overflow or by brz dot net
Published on 2010-04-21T10:30:34Z Indexed on 2010/04/21 10:33 UTC
Read the original article Hit count: 156

Filed under:
|
|
|

I have to find the indentid from the status table based on below two conditions:

1. If there are more than one record having same indentid in status table and the same indentID has count>1 in feasibilitystatus table then I don't want to display the record.
2. If there is only one record of indentid in status table and the same indentID has count>0 in feasibilitystatus table then I don't want to display the record.

Query:

select distinct s.indentid
from status s where
s.status='true'
and s.indentid
not in(select case when count(s.indentid)>1 then (select indentid from feasibilitystatus
group by indentid having count(indentid)>1)
else (select indentid from feasibilitystatus group by
indentid having count(indentid)>0)    
end as indentid from status)

Error:

An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql