我正在进行以下查询
SELECT auth_number,
status
FROM auth_services_cnv auth
WHERE EXISTS
(SELECT 1
FROM
(SELECT COUNT(*) b
FROM auth_services_cnv
WHERE status ='D'
AND auth_number=auth.auth_number
GROUP BY auth_number
) a1 ,
(SELECT COUNT(*) c
FROM auth_services_cnv
WHERE 1 =1
AND auth_number=auth.auth_number
GROUP BY auth_number
) a2
WHERE a1.b=a2.c
);
/
我收到以下错误
ORA-00904:" AUTH"。" AUTH_NUMBER":无效的标识符
00904. 00000 - "%s:无效标识符"
*原因:
*行动:
行错误:42列:21
其实我的要求是这样的
auth_number状态 1个D 1 P 1个D 1个D 2 D. 2 D. 2 D
我需要选择auth_number,其状态为全部' D'。 这意味着我需要选择带有2的auth_number。
请帮帮我。 提前谢谢。
- 桑德亚
答案 0 :(得分:1)
您可以改用:
SELECT auth_number,
status
FROM auth_services_cnv
WHERE auth_number NOT IN (SELECT auth_number
FROM auth_services_cnv
WHERE Status <> 'D')
答案 1 :(得分:0)
这是一个只有oracle的解决方案
SELECT auth_number
FROM auth_services_cnv
MINUS
SELECT auth_number
FROM auth_services_cnv
WHERE Status <> 'D'