Oracle:不是按表达式错误

时间:2015-04-27 16:03:33

标签: oracle

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但仍然无法正常工作。任何人都可以帮助我。

1 个答案:

答案 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;

但是,我必须指出,您正在xy之间进行笛卡尔联接,并且不清楚为什么您使用GROUP BY,因为没有聚合。