When I am trying the below query
select column2
from table1
group by column2
having count(column3) = count(column1) and column5 in (1,2)
I am getting this error:
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
What should I write in order to get result i.e. column2 which satisfies both the conditions
i.e. (count(column3) = count(column1) and column5 in (5,6).
Try this:
select column2
from table1
where column5 in (1,2)
group by column2
having count(column3) = count(column1)
You actually have use part that should be in where condition and not in having as below.
SELECT column2
FROM table1
WHERE column5 IN (1,2)
GROUP BY column2
HAVING COUNT(column3) = COUNT(column1)
Always use aggregate functions in having clause to do the validation within query and not in clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With