PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

LIMITE raggruppato in PostgreSQL:mostra le prime N righe per ogni gruppo?

Nuova soluzione (PostgreSQL 8.4)

SELECT
  * 
FROM (
  SELECT
    ROW_NUMBER() OVER (PARTITION BY section_id ORDER BY name) AS r,
    t.*
  FROM
    xxx t) x
WHERE
  x.r <= 2;