step1:使用city_id相等的条件,将driver_tb左连接city_tb;
step2:限制日期范围为2021年9月,按照城市和日期分组,统计不重复用户的个数。
select city_name, dt, count(distinct driver_id) as driver_num
FROM driver_tb a
LEFT JOIN city_tb b
ON a.city_id = b.city_id
WHERE dt BETWEEN '2021-9-1' and '2021-9-30'
GROUP BY a.city_id, dt;