原SQL如下:
select date_format(date_sub(current_date(), interval 1 day), '%Y%m%d'),
a.app_id,
datediff(date_format(date_sub(current_date(), interval 1 day),
'%Y%m%d'),
date(first_boot_time)),
datediff(date(op_day_id), date(first_boot_time)),
'1160201',
count(distinct imei)
from a
where date_format(first_boot_time, '%Y%m%d') >=
date_format(date_sub(current_date(), interval 10 day), '%Y%m%d')
group by a.app_id,
datediff(date_format(date_sub(current_date(), interval 1 day),
'%Y%m%d'),
date(first_boot_time)),
datediff(date(op_day_id), date(first_boot_time));
因表的字段op_day_id有部分為NULL,進行group by後,還會産生兩條一模一樣的值
解決,處理前,先把a表的控制進行處理