Re: Fetch the latest log for each product

Поиск
Список
Период
Сортировка
От Jeff Hoffmann
Тема Re: Fetch the latest log for each product
Дата
Msg-id 399C21CF.77C26118@propertykey.com
обсуждение исходный текст
Ответ на Fetch the latest log for each product  (Bernie Huang <bernie.huang@ec.gc.ca>)
Список pgsql-sql
Bernie Huang wrote:
> 
> Hi,
> 
> I bet people have asked this question several times, but oh well, please
> do anwser again.  Thanks.  =)
> 
> I have a product table and a log file.
> 
> product_tb
> -----------
> prod_id
> prod_name
> ...
> 
> log_tb
> ---------
> log_id
> prod_id
> cust_id
> transact_date
> ...
> 
> How do I fetch the latest log for each product according to transaction
> date?
> 
> - Bernie


here's how i would do it, i guess.
 select p.prod_name, l.prod_id, max(l.transact_date) as
last_transaction    from log_tb l, prod_tb p   where l.prod_id=p.prod_id 
group by p.prod_name, l.prod_id;

i think that's what you want, at least...

-- 

Jeff Hoffmann
PropertyKey.com


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

Предыдущее
От: Bernie Huang
Дата:
Сообщение: Fetch the latest log for each product
Следующее
От: Webb Sprague
Дата:
Сообщение: Re: Continuous inserts...