SQL : 一屏显示多个表的计数
SQL : Show the count of multiple tables in one screen
我想在一个查询中显示多个表的计数。这是我的不同查询
SELECT count(*) FROM Table_1;
SELECT count(*) FROM Table_2;
SELECT count(*) FROM Table_3;
结果
Table_Name Count
Table_1 51
Table_2 75
Table_3 108
如何实现?
一种简单的方法是 联合 您的查询:
SELECT 'Table_1' Table_Name, count(*) "Count" FROM Table_1
union all
SELECT 'Table_2', count(*) FROM Table_2
union all
SELECT 'Table_3', count(*) FROM Table_3;
一个 select 对具有不同列的 dual 的语句具有每个 table 的 select count(*) 的结果。
SELECT (SELECT Count(*)
FROM table_1) AS count1,
(SELECT Count(*)
FROM table_2) AS count2,
(SELECT Count(*)
FROM table_3) AS count3
FROM dual;
我想在一个查询中显示多个表的计数。这是我的不同查询
SELECT count(*) FROM Table_1;
SELECT count(*) FROM Table_2;
SELECT count(*) FROM Table_3;
结果
Table_Name Count
Table_1 51
Table_2 75
Table_3 108
如何实现?
一种简单的方法是 联合 您的查询:
SELECT 'Table_1' Table_Name, count(*) "Count" FROM Table_1
union all
SELECT 'Table_2', count(*) FROM Table_2
union all
SELECT 'Table_3', count(*) FROM Table_3;
一个 select 对具有不同列的 dual 的语句具有每个 table 的 select count(*) 的结果。
SELECT (SELECT Count(*)
FROM table_1) AS count1,
(SELECT Count(*)
FROM table_2) AS count2,
(SELECT Count(*)
FROM table_3) AS count3
FROM dual;