Use one sql statement to query the total number of multiple tables

SELECT sum(column name 1) column name 1, sum(column name 2) column name 2, sum(column name 3) column name 3 FROM (
 SELECT count( *) column name 1, 0 column name 2, 0 column name 3 FROM table 1 
 -- WHERE plan_uid = 123456
 UNION ALL
 SELECT 0 column name 1, count(*) column name 2, 0 column name 3 FROM table 2
 -- WHERE other_uid = 123456 
 UNION ALL
 SELECT 0 column name 1, 0 column name 2, count(* ) column name 3 FROM table 3
-- WHERE uid = 123456 AND status = 1
) t;

The above sql statement can be implemented, and the total number of data in each table of several tables that are not related to each other can be queried at the same time

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324897153&siteId=291194637