已经用union all的语句查询出来数据,数据有点大,想用count语句来统计相同序号的数量,具体该怎么包进去
union all 的语句
select a.table1 from a
union all
select b.table2 from b
怎么把union all包进count里
select count(1),a.table1 from a
union all
select b.table2 from b
把union all包进count里的语句:
select count(*) from (
select a.table1 from a
union all
select b.table2 from b ) c
如果只是简单获取union all总数:
select
count(*)
from(
select a.table1 from a
union all
select b.table2 from b
)t
如果需要去重获取相同内容分别的数量:
select
myName,
count(*)myNum
from(
select a.table1 as myName from a
union all
select b.table2 as myName from b
)t
group by myName
SELECT tb, COUNT(1) AS num FROM(
SELECT a.table1 AS tb FROM a
UNION ALL
SELECT b.table2 AS tb FROM b
)tmp GROUP BY tb