我有一个问题,必须从多个表中获取行计数.
例如:
SELECT COUNT(*) FROM table1;
SELECT COUNT(*) FROM table1 where condition;
SELECT COUNT(*) FROM table2;
SELECT COUNT(*) FROM table3 where condition;
@H_403_9@
最佳答案
您可以使用UNION
SELECT COUNT(*) FROM table1
UNION
SELECT COUNT(*) FROM table1 where condition;
UNION
SELECT COUNT(*) FROM table2;
UNION
SELECT COUNT(*) FROM table3 where condition;
@H_403_9@
SELECT "COND-1" AS TITLE,COUNT(*) FROM table1
UNION
SELECT "COND-2" AS TITLE,COUNT(*) FROM table1 where condition;
UNION
SELECT "COND-3" AS TITLE,COUNT(*) FROM table2;
UNION
SELECT "COND-4" AS TITLE,COUNT(*) FROM table3 where condition;
@H_403_9@