Eamonn

人生苦短,我用Python

· 默认分类 · · 149次浏览

sql计算多张表的总数据量

SELECT sum(c) from (
  select count(*) as c from table1
  UNION ALL
  select count(*) as c from table2
  UNION ALL
  select count(*) as c from table3
  UNION ALL
  select count(*) as c from table4
)

union(或称为联合)的作用是将多个结果合并在一起显示出来。 union和union all的区别是,union会(去重)自动压缩多个结果集合中的重复结果,而union all则(不去重)将所有的结果全部显示出来,不管是不是重复

评论 (0条)