select 
(
    concat(
    concat(substr(event_date,1,4),'年'),
    concat(substr(event_date,6,2),'月'),
(
case when day(event_date)<=9 then '上旬'
when day(event_date)>9 and day(event_date)<=19  then '中旬'
when day(event_date)>=20 then '下旬'
end))) dt_range,
count(distinct device_id) as cnt
from 
question_practice_detail
group by dt_range
order by substr(dt_range,6,2) desc, cnt desc

写连接起来有点小复杂,其实理清楚了,也没啥。