网上使用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']即可。

相关文章:

  • 2022-01-01
  • 2022-12-23
  • 2021-06-15
  • 2021-08-30
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-04-08
  • 2021-05-24
  • 2021-11-02
  • 2021-06-04
  • 2022-12-23
  • 2022-03-01
相关资源
相似解决方案