网上使用union all 查询记录总条数的参考资料比较少,所以记录下来,以便有同样需求的人使用。
$rs_num = Db::query("select sum(a.b) as num from ( select count(1) as b from table1 where afrom = '".condition1."' UNION ALL select count(1) as b from table2 where afrom = '".condition2."' UNION ALL select count(1) as b from table3 diyanye where afrom = '".condition3."' ) as a");
要注意 标记成红色的部分。在使用总条数的地方,用 $rs_num['num']即可。