Re: SQL Query

Поиск
Список
Период
Сортировка
От Mark Wimer
Тема Re: SQL Query
Дата
Msg-id OF27C227F3.63C28F73-ON852573B0.005F68AC-852573B0.005F8CEF@usgs.gov
обсуждение исходный текст
Ответ на SQL Query  (Ashish Karalkar <ashish_postgre@yahoo.co.in>)
Список pgsql-novice

See if this works; the max aggregate in the subquery could be just about any function, since it's only going to join to one row.



select max(m1.output_date), m1.parent_id, max(m2.output_id) as latest_output
from my_table M1 inner join (select output_date, output_id, parent_ID from my_table) as M2
        on m1.output_date = m2.output_date and m1.parent_ID = m2.parent_ID
Where M1.output_date < now()
Group by m1.parent_id


-- Mark




Ashish Karalkar <ashish_postgre@yahoo.co.in>
Sent by: pgsql-novice-owner@postgresql.org

12/13/2007 04:47 AM

To
pgsql-novice@postgresql.org, ashish.karalkar@netcore.co.in
cc
Subject
[NOVICE] SQL Query





Hello List member,
I have a table which ha sfollowing structure

my_table:
(
   output_id serial priimary key,
   parent_id int,
   output_date timesatmp
)

parent_table:

(parent_id int,
parent desc
)

the my_table contains data for previous as well as future output dates.
for single parent there may be multiple rows.

I want to retrieve all the output_id  which are having latest output_date but less than now() (no future output_dates) group by  parent_id

Thanks in advance

With Regards
Ashish...











 


Chat on a cool, new interface. No download required. Click here.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Is now() atomic?
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: remote user