My goal is to create a condition where the number of unique rows equals 3 or more,
For an instance - if I got the result:
| id |
1
2
3
then there are 3 rows return true. (for the existence part I'll use EXISTS)
I've tried to use COUNT(*) and DISTINCT to count all the different unique rows, but as I want to use condition -
- using
WHEREis impossible due theCOUNTfunction - nor using
HAVING- because there's a need to useGROUP BYfirst, which cause theCOUNT(*)=1.
Another requirement - is to use postgresql at version 9.4
My latest attempt which returns nothing because COUNT(*)=1
exists(
select count(*)
from (select sid, bno
from schedule scj inner join revent on scj.eid = revent.reid
where 12345 = cno AND 'hello' = sid) as foo
group by sid, bno
having count(*)>=3)