Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Gavin Flower
On 07/10/11 03:03, Rich Shepard wrote: On Thu, 6 Oct 2011, David Johnston wrote: Missing the FROM before chemistry D'oh! Obviously not yet sufficiently cafinated this morning. [...] You just infringed my patent on making unprovoked stupid mistakes in posts to the Pg mailing lists! I th

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Thomas Kellerer
Rich Shepard, 06.10.2011 15:13: I was unaware of the windows functions. I see the document page for 9.0.5 so I'll carefully read that and upgrade from 9.0.4 (which may also have this function; I'll check). Windowing functions are available since 8.4 -- Sent via pgsql-general mailing list (pg

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Thu, 6 Oct 2011, David Johnston wrote: Missing the FROM before chemistry D'oh! Obviously not yet sufficiently cafinated this morning. Also, with the window function can I limit the output to a single str_name and param? Not directly. After you create the windowed result you can turn

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread David Johnston
On Oct 6, 2011, at 9:34, Rich Shepard wrote: > On Wed, 5 Oct 2011, David Johnston wrote: > >> 2) "Window" - max(quant) OVER (PARTITION BY ...) > > Hmm-m-m. I have a problem here emulating the example on the document page. > Regardless of which column is first after SELECT postgres tells me th

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Wed, 5 Oct 2011, David Johnston wrote: 2) "Window" - max(quant) OVER (PARTITION BY ...) Hmm-m-m. I have a problem here emulating the example on the document page. Regardless of which column is first after SELECT postgres tells me that column does not exist. select site_id, sample_date,

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Wed, 5 Oct 2011, David Johnston wrote: "Max" is an aggregate function and thus requires one of: 1) GROUP BY 2) "Window" - max(quant) OVER (PARTITION BY ...) To be present in the query. David, I was unaware of the windows functions. I see the document page for 9.0.5 so I'll carefully rea

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-06 Thread Rich Shepard
On Wed, 5 Oct 2011, Chris Curvey wrote: Based on your subject line, I'm guessing that you want something like this: select quant, param, site_id, sample_date, str_name from chemistry where param = 'TDS' and str_name = 'BurrowCrk' and quant = (select max(quant) from chemistry where param = 'TDS'

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-05 Thread Chris Curvey
On Wed, Oct 5, 2011 at 7:34 PM, Rich Shepard wrote: > A table (chemistry) has columns named site_id, sample_date, param, quant, > and str_name (among other columns). I want to find the site_id, > sample_date, > and quant for a specific str_name and param. I cannot get the proper syntax > in the S

Re: [GENERAL] Selecting All Columns Associated With Maximum Value of One Column

2011-10-05 Thread David Johnston
On Oct 5, 2011, at 19:34, Rich Shepard wrote: > A table (chemistry) has columns named site_id, sample_date, param, quant, > and str_name (among other columns). I want to find the site_id, sample_date, > and quant for a specific str_name and param. I cannot get the proper syntax > in the SELECT s