天天看点

SQL日常

一个rq(日期)字段

需要统计A表中的数据数

需要统计B表中满足什么条件的数据数

A表与B表中的rq字段没有关系

如果以A表rq为主,B表中数据可能统计的不准确

如果以B表rq为主,A表中数据可能统计的不准确

解决办法:

select count(1) table_a_num,0 table_b_num from A

union all 

select 0 table_a_num,count(1) table_b_num from B

外面套上一层合计,加上group by即可