How can I calculate differences between values

Поиск
Список
Период
Сортировка
От A B
Тема How can I calculate differences between values
Дата
Msg-id dbbf25900911100640p7a62c0f8w9d528c0ef3e3e0a9@mail.gmail.com
обсуждение исходный текст
Ответы Re: How can I calculate differences between values
Re: How can I calculate differences between values
Список pgsql-general
Hello there!

I have a table    foo( userid integer, data integer); with the
constraint unique(userid,data)

 Now I wish to select one userid and calculate the differences between
the data -values (when they are sorted) .
For example
if the table contains:

4, 100
5, 200
5, 210
5, 231


I want the values

5,10
5,21

what should happen to the  4,100 record you may ask, I will try to
exclude that case  by requireing each userid to have at least two data
values.

The question is now: is there a clever and efficient way of
calculating these differences in data values?

The only thing I can think of is picking a data value and
select min(data) from foo where userid=5 and data>200
and then calculate the difference and do what I want with it, and the
repeat this process with the last selected data value.
I guess that will work, but I'm curious, are there other ways?

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

Предыдущее
От: Richard Broersma
Дата:
Сообщение: Re: Editor for sgml files
Следующее
От: Greg Stark
Дата:
Сообщение: Re: Incremental Backups in postgres