select case when x.a in (select y.c from join2) then x.a end, x.b, x.c, y.a, z.c
from join1 x, join2 y, join3 z where x.a = z.a
group by x.a, x.b, x.c, y.a, z.c order by x.c;
在运行此查询时,我按表达式获取error ORA-00979
组。我已经尝试过从组中删除x.a但仍然无法正常工作。任何人都可以帮助我。
答案 0 :(得分:0)
您需要在GROUP BY
子句中使用此表达式而不是x.a
:
case when x.a in (select y.c from join2) then x.a end
所以把它们放在一起:
SELECT CASE WHEN x.a IN ( SELECT y.c FROM join2) THEN x.a END
, x.b, x.c, y.a, z.c
FROM join1 x, join2 y, join3 z
WHERE x.a = z.a
GROUP BY CASE WHEN x.a IN ( SELECT y.c FROM join2) THEN x.a END
, x.b, x.c, y.a, z.c
ORDER BY x.c;
但是,我必须指出,您正在x
和y
之间进行笛卡尔联接,并且不清楚为什么您使用GROUP BY
,因为没有聚合。