我有一个问题,必须从多个表中获取行计数.
例如:
SELECT COUNT(*) FROM table1;
SELECT COUNT(*) FROM table1 where condition;
SELECT COUNT(*) FROM table2;
SELECT COUNT(*) FROM table3 where condition;
最佳答案
您可以使用UNION
原文链接:https://www.f2er.com/mysql/531903.htmlSELECT COUNT(*) FROM table1
UNION
SELECT COUNT(*) FROM table1 where condition;
UNION
SELECT COUNT(*) FROM table2;
UNION
SELECT COUNT(*) FROM table3 where condition;
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;