Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E5DAC4768D5 for ; Wed, 23 Oct 2002 10:31:08 -0400 (EDT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id BF1AD47689D for ; Wed, 23 Oct 2002 10:31:07 -0400 (EDT) Received: from klaster.net (pq84.krakow.cvx.ppp.tpnet.pl [213.76.41.84]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 349A52B4D8; Wed, 23 Oct 2002 16:24:37 +0200 (CEST) Message-ID: <3DB6B41C.8090409@klaster.net> Date: Wed, 23 Oct 2002 16:37:16 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; PL; rv:1.1) Gecko/20020826 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Carlos Sousa Cc: pgsql-sql@postgresql.org Subject: Re: problem with a query References: Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/296 X-Sequence-Number: 10013 Użytkownik Carlos Sousa napisał: > hi to all > > i need to do a query to a small postgres database > my best efort to the pretended query is in the attached file 'query.txt' > but i need that some rows don't be selected of thouse that the query > returns. > > i send in another attached file 'result.txt' with the query result. > looking at content of the file you will see some notes at the end of the > table (#..) > > the database as the data to enable the constrution of a school class > schedule. > > In the 'result.txt' all the rows with max=0 were the fisrt to be > inserted do the database. each row represent as example math pratical > starting at 8:30 for 1:30 at room 3.15 in the bilding CP > > the rows with max!=0 (1,2,3,...) mean that content of an insert with > max=0 was changed [ex diferent time (fiel to_char) or room (field sala) > or bilding (field edificio)of the school class]. row with max=1 is a > substitution to a row with max=0, row with max=2 substitutes row with > max=1 and ... > > my objective is to obtain all the rows that were not substituted and the > ones that represent the last alteration to the shedule > > i hope the problem was understod I'm not sure, but you want to get data for each room (field "sala") with the biggest field "indice"? you can do this with query: select distinct on (indice) ... from ... order by sala,indice desc; Result of this query is - one row per one "sala". If there are more then 1 records in database with the same "sala", you get record with biggest "indice". You don't need to use max(indice) and group by... Tomasz Myrta