Search Postgresql Archives

Picking the first of an order in an aggregate query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a query

  SELECT grouping_field, MIN(field_a), MIN(field_b)
  FROM ...
  GROUP BY grouping_field

But, instead of picking the MIN field_a and MIN field_b, I'd like to
pick field_a and field_b from the first record, according to an order
I'll specify.  In pseudo-SQL, it would be something like this:

  SELECT grouping_field, FIRST(field_a), FIRST(field_b)
  FROM ...
  ORDER BY field_c DESC, field_d ASC, myfunc(field_e) ASC
  GROUP BY grouping_field

How can I do that with Postgres?


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux