我正在创建该查询。在哪里设置“ SELECT”?
(SELECT COUNT(B.USER_ID)
FROM USER_LIST B, USER_INFO A
WHERE B.PHONE_NUM not in ('11100000')
AND B.USER_ID = A.USER_ID) USERCOUNT,
(SELECT COUNT(B.USER_ID) FROM USER_LIST B, USER_INFO A
AND B.PHONE_NUM in ('11100000')
AND B.USER_ID = A.USER_ID) BLACKUSERCOUNT
Oracle / PLSQL: ORA-00933 错误消息。
但是,如果我一一运行,那是可行的。如何合并该查询?
答案 0 :(得分:2)
您可以使用以下命令包装语句:
以
开头 select
最后
from dual
答案 1 :(得分:0)
另一种选择是:它将显示两行数据,每一行的第一列(其标签为what
)都将显示其代表的内容。
SELECT 'usercount' what, COUNT (b.user_id) cnt
FROM user_list b JOIN user_info a ON a.user_id = b.user_id
WHERE b.phone_num NOT IN ('11100000')
UNION ALL
SELECT 'blackusercount' what, COUNT (b.user_id)
FROM user_list b JOIN user_info a ON a.user_id = b.user_id
WHERE b.phone_num IN ('11100000');
或者,也许更好,通过只查询一次表来节省一些CPU
SELECT SUM (CASE WHEN b.phone_num NOT IN ('1110000') THEN 1 ELSE 0 END) usercount,
SUM (CASE WHEN b.phone_num IN ('1110000') THEN 1 ELSE 0 END) blackusercount
FROM user_list b JOIN user_info a ON a.user_id = b.user_id;