pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
problem with a query
2+ messages / 2 participants
[nested] [flat]

* problem with a query
@ 2002-10-23 14:05  Carlos Sousa <carlosdsousa@hotmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Carlos Sousa @ 2002-10-23 14:05 UTC (permalink / raw)
  To: pgsql-sql

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
thanks for your time



_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

Attachments:

  query.txt (application/octet-stream, 720B) download

  result.txt (application/octet-stream, 4.2K) download

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: problem with a query
@ 2002-10-23 14:37  Tomasz Myrta <jasiek@klaster.net>
  parent: Carlos Sousa <carlosdsousa@hotmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tomasz Myrta @ 2002-10-23 14:37 UTC (permalink / raw)
  To: Carlos Sousa <carlosdsousa@hotmail.com>; +Cc: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-10-23 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-23 14:05 problem with a query Carlos Sousa <carlosdsousa@hotmail.com>
2002-10-23 14:37 ` Tomasz Myrta <jasiek@klaster.net>

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