原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表的控制进行处理