Premium problem81. Three Consecutive Filing Years

Medium Locked

filings(company_id, filing_year)

Return the company_id of every company with filings in at least three consecutive years, ordered by company_id. Several filings in one year count once.

Return each company once even if it has two separate qualifying runs.

Same gaps-and-islands shape as the date version, except the gap is an integer so no date arithmetic is needed.

Tables

filings

company_id  filing_year
----------  -----------
1           2020
1           2021
1           2021
1           2022
2           2020
2           2021
2           2023
2           2024
... 7 more row(s)

Expected result

company_id
----------
1
3

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query