3 回答
TA贡献1744条经验 获得超4个赞
SELECT (
SELECT COUNT(*)
FROM tab1
) AS count1,
(
SELECT COUNT(*)
FROM tab2
) AS count2
FROM dual
TA贡献1790条经验 获得超9个赞
只是因为它略有不同:
SELECT 'table_1' AS table_name, COUNT(*) FROM table_1
UNION
SELECT 'table_2' AS table_name, COUNT(*) FROM table_2
UNION
SELECT 'table_3' AS table_name, COUNT(*) FROM table_3
它给出了换位的答案(每张表一行而不是一列),否则我认为这没有太大不同。我认为在性能方面,它们应该是等效的。
TA贡献1829条经验 获得超6个赞
其他略有不同的方法:
with t1_count as (select count(*) c1 from t1),
t2_count as (select count(*) c2 from t2)
select c1,
c2
from t1_count,
t2_count
/
select c1,
c2
from (select count(*) c1 from t1) t1_count,
(select count(*) c2 from t2) t2_count
/
添加回答
举报