题解 | #任意两个连续自然月练题次数大于1的用户#
任意两个连续自然月练题次数大于1的用户
https://www.nowcoder.com/practice/a4cea6942a4f4354b0a0181aa5f446d2
with t as (select device_id, date_format(event_date,'%Y-%m') as d from question_practice_detail group by device_id, date_format(event_date,'%Y-%m') having count(id) > 1), g as (select device_id, date_format(date_sub(event_date, INTERVAL 1 month),'%Y-%m') as d from question_practice_detail group by device_id, date_format(date_sub(event_date, INTERVAL 1 month),'%Y-%m') having count(id) > 1) select distinct t.device_id from t inner join g on t.device_id = g.device_id and t.d = g.d order by t.device_id desc;