select *
from(
select distinct customer_id,
dense_rank()over( order by customer_id asc) rn_low,
dense_rank()over( order by customer_id desc) rn_high
from subscriptions as s
) t1
where rn_low <= 5 or rn_high <= 5
order by customer_id