In Postgres 13 can use with ties
:
select t.*
from t
order by customer_id
fetch first 3 rows with ties;
In earlier versions you can use in
:
select t.*
from t
where t.customer_id in (select t2.customer_id
from t t2
order by t2.customer_id
limit 3
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…