我得到 ORA-00904 'c' 无效标识符错误。这个别名有什么问题?
select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y' AND JOINT.c > 1
GROUP BY NO;
我想你想获取那些计数 > 1 的记录。所以你不能Indentifier C
在同一个查询的WHERE
子句中使用。
select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y'
GROUP BY NO
HAVING COUNT(JOINT_NO)>1;
c
table 中不存在列JOINT
,导致您收到错误消息。
像这样更改您的查询:
select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y'
GROUP BY NO
HAVING count(JOINT_NO) > 1;
您可以在 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