希望这会很快回答。我是SQL的新手,所以在这方面苦苦挣扎,可能会遗漏一些明显的东西。我有以下查询,该查询在单独的结果中返回行计数,但是我想将结果放入XLS中。实现此目标的最佳方法是什么?
select count(*) as "table_1" FROM table_1
select count(*) as "table_2" FROM table_2
select count(*) as "table_3" FROM table_3
select count(*) as "table_4" FROM table_4
select count(*) as "table_5" FROM table_5
select count(*) as "table_6" FROM table_6
select count(*) as "table_7" FROM table_7
select count(*) as "table_8" FROM table_8
select count(*) as "table_9" FROM table_9
select count(*) as "table_10" FROM table_10
非常感谢!
感谢您的帮助,这就是我要带给我所需的东西。
我知道那将是相当简单的事情!
SELECT 'table_1' as "Table", count (*) as "Count" FROM table_1 union all
SELECT 'table_2' as "Table", count (*) as "Count" FROM table_2 union all
SELECT 'table_3' as "Table", count (*) as "Count" FROM table_3 union all
SELECT 'table_4' as "Table", count (*) as "Count" FROM table_4 union all
SELECT 'table_5' as "Table", count (*) as "Count" FROM table_5 union all
SELECT 'table_6' as "Table", count (*) as "Count" FROM table_6 union all
SELECT 'table_7' as "Table", count (*) as "Count" FROM table_7 union all
SELECT 'table_8' as "Table", count (*) as "Count" FROM table_8 union all
SELECT 'table_9' as "Table", count (*) as "Count" FROM table_9 union all
SELECT 'table_10' as "Table", count (*) as "Count" FROM table_10
您可以通过两种方式执行此操作,即使用union语句和将子查询与选择语句一起使用
联合会将所有结果合并到一个包含多行的表中
select count(*) , 'Table1' as tablename FROM table_1
union all
select count(*), 'Table2' as tablename FROM table_2
union all
select count(*) ,'Table3' as tablename FROM table_3
.....
.....
子查询将返回多列的一行
SELECT
(SELECT COUNT(*) FROM table_1) as 'Table1',
(SELECT COUNT(*) FROM table_2) as 'Table2',
(SELECT COUNT(*) FROM table_3) as 'Table3'
......
......
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句