使用一条sql查询多个表中的记录数


方法一:

 select t1.num1,t2.num2,t3.num3 from 
  (select count(*) num1 from table1) t1,
  (select count(*) num2 from table2) t2,
  (select count(*) num3 from table3) t3

方法二:

select sum(t.num1),sum(t.num2),sum(t.num3) from (
    select count(*) num1,0 as num2,0 as num3 from table1 
  union 
    select 0 as num1,count(*) num2,0 as num3 from table2
  union 
    select 0 as num1,0 as num2,count(*) num3 from table3
) t

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM