pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Patrick Jacquot <patrick.jacquot@anpe.fr>
To: marchesini@unipg.it
Cc: pgsql-sql@postgresql.org
Subject: Re: simple problem???
Date: Fri, 21 Jul 2006 11:09:45 +0200
Message-ID: <44C099D9.5060608@anpe.fr> (raw)
In-Reply-To: <1153407157.5192.64.camel@geoivan>
References: <1153407157.5192.64.camel@geoivan>

ivan marchesini wrote:

>Dear users....
>It's a simple problem I think (and I hope  :-)
>
>I have a table like this:
>A|B|C
>1|2|20
>1|3|10
>1|4|21
>2|3|12
>2|4|22
>3|4|23
>
>where the first two column are a combination without repetition (with
>k=2) of the numbers 1,2,3,4
>for each pair I have a value in the column C.
>
>I would want a select that can extract these records:
>
>1|3|10
>2|3|12
>3|4|23
>
>
>i.e. the select must look into the A field first and: 
>-select all records where A=1, 
>-find, into this selection, the record where there's the minimum value
>of the field C 
>-print all the fields for this record.
>
>then
>
>-select all records where A=2
>-find, into this selection, the record where there's the minimum value
>of the field C 
>-print all the fields of this record.
>
>and so on...
>
>using 
>SELECT a,MIN(c) FROM table GROUP BY a
>
>is a partial solution because I can't see the value of B
>and I obtain:
>
>1|10
>2|12
>3|23
>
>How can I do for plotting also the value of B???
>
>Thank you very much
>
>Ivan
>  
>
Maybe you could try
Select distinct on (a,b) a,b,c from(select * from table order by A,C)
The distinct on construct is a postgreSql-ism

Cordialement
-- 
Patrick




view thread (10+ messages)

Message-ID: <44C099D9.5060608@anpe.fr>
Permalink:  ../44C099D9.5060608@anpe.fr/
Also on:    postgresql.org/message-id/44C099D9.5060608@anpe.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: patrick.jacquot@anpe.fr, marchesini@unipg.it
  Subject: Re: simple problem???
  In-Reply-To: <44C099D9.5060608@anpe.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox