我收到ORA-00904'c'无效的标识符错误。这个别名有什么问题?
select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y' AND JOINT.c > 1
GROUP BY NO;
答案 0 :(得分: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;
答案 1 :(得分:2)
表c
中没有列JOINT
,导致您收到错误消息。
更改您的查询:
select NO, count(JOINT_NO) as c
from JOINT
WHERE HOLDER = 'Y'
GROUP BY NO
HAVING count(JOINT_NO) > 1;
答案 2 :(得分:0)
您可以在FROM子句中使用subselect(subquery):
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