on t1.cl_id=dev.device_id and t1.partition_date = dev.partition_date
on t1.cl_id=dev.device_id and t1.partition_date = dev.partition_date
GROUP BY t1.query,active_type,device_os_type,channel
GROUP BY t1.query,active_type,device_os_type,channel
)t6
)t6
on t1.query=t6.query and t1.active_type=t6.active_type and t1.device_os_type = t6.device_os_type AND t1.channel = t6.channel""".format(last_30_day_str=last_30_day_str,today_str=today_str,
on t1.query=t6.query and t1.active_type=t6.active_type and t1.device_os_type = t6.device_os_type AND t1.channel = t6.channel