SELECT sum(num) as num, t.field4 from
(
(SELECT count(*) as num, field4 from `dx_common_member_profile_archive` as pa
group by field4 )
union
(select count(*) as num, field4 from `dx_common_member_profile` as p group by
field4 )
) as t
GROUP BY t.field4
ORDER BY t.num DESC
大概原理是:
每个表分组统计出来使用union来合并成一个集合,
然后再次用分组进行统计即可