当我尝试以下查询时
select column2
from table1
group by column2
having count(column3) = count(column1) and column5 in (1,2)
我收到此错误:
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
我应该写什么来获得结果,即满足两个条件的column2
i.e. (count(column3) = count(column1) and column5 in (5,6)
。
答案 0 :(得分:5)
试试这个:
select column2
from table1
where column5 in (1,2)
group by column2
having count(column3) = count(column1)
答案 1 :(得分:3)
你实际上使用的部分应该处于条件而不是如下所示。
SELECT column2
FROM table1
WHERE column5 IN (1,2)
GROUP BY column2
HAVING COUNT(column3) = COUNT(column1)
始终在having子句中使用聚合函数在查询中而不是在子句中进行验证。
答案 2 :(得分:0)
您正在使用having和group by子句。这个没关系。
但是您可以在查询中添加where子句以获取以下条件
column5 in (1,2)
如下所示重构您的查询后,我希望您能获得解决方案
select column2 where column5 in (1,2) -- here is your where condition
from table1
group by column2
having count(column3) = count(column1)