使用一条sql语句查询多表的总数
SELECT sum(列名1) 列名1,sum(列名2) 列名2,sum(列名3) 列名3 FROM ( SELECT count(*) 列名1,0 列名2,0 列名3 FROM 表1 -- WHERE plan_uid = 123456 UNION ALL SELECT 0 列名1,count(*) 列名2,0 列名3 FROM 表2 -- WHERE other_uid = 123456 UNION ALL SELECT 0 列名1,0 列名2,count(*) 列名3 FROM 表3
-- WHERE uid = 123456 AND status = 1
) t;
以上sql语句即可实现,同时查询互相不关联的几个表的每个表的数据总数