多表并集统计
主要分享一下多表做并集之后进行统计的方法。
先将多个表做并集,不创建视图不建表。
select *
from (
select key as ID
from a
where key > 999
union all
select num as ID
from b
where num > 999
)
where ID < 100
分组统计
select count(ID)
from (
select key as ID,
class
from a
where key > 999
union all
select num as ID ,
class
from b
where num > 999
)
where ID < 100
group by class
之前uion习惯了只用来合并显示,并没有跟join的用法关联起来,其实union我觉得应该入join系的。