Re: I need help creating a query

Поиск
Список
Период
Сортировка
От Dann Corbit
Тема Re: I need help creating a query
Дата
Msg-id D425483C2C5C9F49B5B7A41F8944154757DA72@postal.corporate.connx.com
обсуждение исходный текст
Ответ на I need help creating a query  ("Sergio Duran" <sergioduran@gmail.com>)
Список pgsql-general

The query date supplied should be applied against start date and then take the minimum record from that set.

 


From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Sergio Duran
Sent: Thursday, July 13, 2006 12:20 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] I need help creating a query

 

Hello,

I need a little help creating a query, I have two tables, worker and position, for simplicity sake worker only has its ID and its name, position has the ID of the worker, the name of his position, a date, and his salary/

worker:   worker_id, name
position: position_id, worker_id, position, startdate, salary

If I perfom a query joining both tables, I can obtain all the workers and the positions the've had.

SELECT name, startdate, position,  salary FROM worker JOIN position USING(worker_id);
worker1 | 2001-01-01 | boss             | 999999
worker2 | 2001-01-01 | cleaning        | 100
worker2 | 2006-04-01 | programmer   | 20000
worker2 | 2006-07-04 | management | 25000

so far so good, now I need to obtain all the workers only with the position they had on a given date.
if I wanted to know the positions on '2006-05-01' it would return
worker1 | 2001-01-01 | boss             | 999999
worker2 | 2006-04-01 | programmer   | 20000

Maybe I only need some insight here, maybe it should be done with 2 queries, maybe it should be done with functions, I don't know.

Thanks

В списке pgsql-general по дате отправления:

Предыдущее
От: "Sergio Duran"
Дата:
Сообщение: I need help creating a query
Следующее
От: "Marco Bizzarri"
Дата:
Сообщение: Clustering and backup with large objects