我有一个Oracle数据库,我需要运行带有子选择的select,但是,它们都不共享同一个表Universe,因此,我需要做这样的事情:
SELECT (
SELECT COUNT(*)
FROM user_table
) AS tot_user,
(
SELECT COUNT(*)
FROM cat_table
) AS tot_cat,
(
SELECT COUNT(*)
FROM course_table
) AS tot_course
我知道这在其他数据库中是可行的,但对于Oracle我需要这样的东西。
有人可以帮忙吗?
答案 0 :(得分:2)
要在oracle中使用此功能,请将from dual
添加到结尾:
SELECT (SELECT COUNT(*)
FROM user_table
) AS tot_user,
(SELECT COUNT(*)
FROM cat_table
) AS tot_cat,
(SELECT COUNT(*)
FROM course_table
) AS tot_course
FROM dual;
与数据库无关的编写查询的方法是:
select tot_user, tot_cat, tot_course
from (SELECT COUNT(*) as tot_user
FROM user_table
) u cross join
(SELECT COUNT(*) as tot_cat
FROM cat_table
) c cross join
(SELECT COUNT(*) as tot_course
FROM course_table
) ct;