3

我得到 ORA-00904 'c' 无效标识符错误。这个别名有什么问题?

select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y' AND JOINT.c > 1
GROUP BY NO;
4

3 回答 3

3

我想你想获取那些计数 > 1 的记录。所以你不能Indentifier C在同一个查询的WHERE子句中使用。

select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y'
GROUP BY NO
HAVING COUNT(JOINT_NO)>1;
于 2012-11-23T11:09:55.670 回答
2

ctable 中不存在列JOINT,导致您收到错误消息。

像这样更改您的查询:

select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y'
GROUP BY NO
HAVING count(JOINT_NO) > 1;
于 2012-11-23T11:10:07.667 回答
0

您可以在 FROM 子句中使用子选择(子查询):

 select T1.NO,T1.c
    from
    (
      select NO, count(JOINT_NO) as c
      from JOINT
      WHERE HOLDER = 'Y' 
      GROUP BY NO
    ) as T1
    where T1.c > 1

你也可以使用

    select NO, count(JOINT_NO) as c
    from JOINT
    WHERE HOLDER = 'Y'
    GROUP BY NO
    HAVING COUNT(JOINT_NO)>1
于 2020-04-07T06:29:53.897 回答