题解 | #每月各旬有多少人练题#
每月各旬有多少人练题
https://www.nowcoder.com/practice/48c8bef6528d4d838e9646682e2b395d
with cte as ( select left(event_date,7) as dt_month, case when right(event_date,2)<=9 then '上旬' when right(event_date,2)<=19 then '中旬' else '下旬' end as dt_days ,count(distinct device_id) as cnt from question_practice_detail group by dt_month,dt_days ) select concat(left(dt_month,4),'年',mid(dt_month,6,2),'月',dt_days) as dt_range,cnt from cte order by dt_month desc,cnt desc