Re: [GENERAL] Picking the first of an order in an aggregate query

2013-01-08 Thread Vincent Veyron
Le lundi 31 décembre 2012 à 20:55 -0500, Robert James a écrit : > On 12/31/12, François Beausoleil wrote: > > > > Le 2012-12-31 à 15:38, Robert James a écrit : > > > >> DISTINCT is a very simple solution! > >> But I have one problem: In addition to the FIRST fields, I also do > >> want some aggreg

Re: [GENERAL] Picking the first of an order in an aggregate query

2012-12-31 Thread Robert James
On 12/31/12, François Beausoleil wrote: > > Le 2012-12-31 à 15:38, Robert James a écrit : > >> DISTINCT is a very simple solution! >> But I have one problem: In addition to the FIRST fields, I also do >> want some aggregate functions. More accurately, it would be: >> >> SELECT grouping_field, FIR

Re: [GENERAL] Picking the first of an order in an aggregate query

2012-12-31 Thread François Beausoleil
Le 2012-12-31 à 15:38, Robert James a écrit : > DISTINCT is a very simple solution! > But I have one problem: In addition to the FIRST fields, I also do > want some aggregate functions. More accurately, it would be: > > SELECT grouping_field, FIRST(field_a), FIRST(field_b), SUM(field_x), > MAX(

Re: [GENERAL] Picking the first of an order in an aggregate query

2012-12-31 Thread Robert James
DISTINCT is a very simple solution! But I have one problem: In addition to the FIRST fields, I also do want some aggregate functions. More accurately, it would be: SELECT grouping_field, FIRST(field_a), FIRST(field_b), SUM(field_x), MAX(field_y) ... How should I do that? Should I do two queries

Re: [GENERAL] Picking the first of an order in an aggregate query

2012-12-31 Thread Tom Lane
Jack Christensen writes: > On 12/31/2012 8:33 AM, Robert James wrote: >> 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? > select distinct on (grouping_f

Re: [GENERAL] Picking the first of an order in an aggregate query

2012-12-31 Thread Jack Christensen
On 12/31/2012 8:33 AM, Robert James wrote: 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 s

[GENERAL] Picking the first of an order in an aggregate query

2012-12-31 Thread Robert James
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 li