使用一條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