find top max and top min

PHOTO EMBED

Thu Apr 21 2022 04:04:25 GMT+0000 (Coordinated Universal Time)

Saved by @Bambibo9799

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
content_copyCOPY