select
    distinct t.电话号码
from
    (select
        电话号码,
        substr(电话号码,5,1) as d5,
        substr(电话号码,6,1) as d6,
        substr(电话号码,7,1) as d7,
        substr(电话号码,8,1) as d8
    from
        电话费用表
    where
        月份 between 201701 and 201710) t
where 
    t.d5 between 1 and 9
    and t.d6 between 1 and 9
    and t.d7 between 1 and 9
    and t.d8 between 1 and 9
    and ((d5 = d6 and d7 = d8)
    or (d5 = d7 and d6 = d8)
    or (d5 = d6 = d7 = d8))