Re: Need to subtract values between previous and current row

Поиск
Список
Период
Сортировка
От Joe
Тема Re: Need to subtract values between previous and current row
Дата
Msg-id 1166187935.691.2.camel@pampa
обсуждение исходный текст
Ответ на Need to subtract values between previous and current row  ("Partha Guha Roy" <partha.guha.roy@gmail.com>)
Список pgsql-sql
On Fri, 2006-12-15 at 18:27 +0600, Partha Guha Roy wrote:
> I have a table that contains data like this:
> 
> ID           ATIME (MM/dd/yyyy)
> ==          ====
> 1            10/12/2006
> 2            10/14/2006
> 3            10/18/2006
> 4            10/22/2006 
> 5            10/30/2006
> 
> Now I need a query that will subtract atime of row 1 from row 2, row2
> from row3  and so on...
> 
> Can anyone please help?

How about something like this

select x.id, x.atime, x.atime - y.atime as diff
from yourtable x, yourtable y
where x.id + 1 = y.id;

Joe



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

Предыдущее
От: Ragnar
Дата:
Сообщение: Re: Need to subtract values between previous and current row
Следующее
От: "Marc Mamin"
Дата:
Сообщение: Re: Need to subtract values between previous and current row