Re: obtain the difference between successive rows

Поиск
Список
Период
Сортировка
От Berend Tober
Тема Re: obtain the difference between successive rows
Дата
Msg-id 5082CB29.9070300@computer.org
обсуждение исходный текст
Ответ на Re: obtain the difference between successive rows  (Thalis Kalfigkopoulos <tkalfigo@gmail.com>)
Ответы Re: obtain the difference between successive rows  (Raymond O'Donnell <rod@iol.ie>)
Список pgsql-general
Thalis Kalfigkopoulos wrote:
> SELECT current_meter_reading - lag(current_meter_reading) OVER(ORDER
> BY current_reading_date) AS kWh_diff, extract('days' FROM
> current_reading_date - lag(current_reading_date) OVER(ORDER BY
> current_reading_date)) as num_service_days FROM mytable;

How would you get the previous reading (and perhaps the previous
read date) to also appear on the same output row? The sample
table with the subtraction I showed for illustration is literally
what is printed on the bill ... they are not just presenting the
quantity used and the number of days, but actually the dates and
meter readings used to do the arithmetic.




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

Предыдущее
От: Thalis Kalfigkopoulos
Дата:
Сообщение: Re: obtain the difference between successive rows
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: obtain the difference between successive rows