select device_id
from
    (
        select
            a.device_id,
            n
        from
            (
                select
                    device_id,
                    date_format(date_sub(event_date, interval 1 month), '%Y%m') as n
                from
                    question_practice_detail
            ) a
            join (
                select
                    device_id,
                    date_format (event_date, '%Y%m') next
                from
                    question_practice_detail
            ) b on a.device_id = b.device_id
            and a.n = b.next
        group by
            a.device_id,
            n
        having
            count(1) > 2
    ) z
order by
    device_id desc;