nth_value and row_number in a partition

Поиск
Список
Период
Сортировка
От Olivier Leprêtre
Тема nth_value and row_number in a partition
Дата
Msg-id 015201d3960a$a2db0b60$e8912220$@gmail.com
обсуждение исходный текст
Ответы Re: nth_value and row_number in a partition
Список pgsql-sql

Hi,

 

I can't find the right syntax to use simultaneously nth_value and row_number in a partition.

I have a table with roads and their orders, a road segment name and two values v1 and v2

I want to decrement first_value v1 of each partition with the current record value v2 of the partition in a third column v3 in the same record. So I thought that I could combine and row_number which returns "number of the current row within its partition, counting from 1" with nth_value

 

My problem is that I get either syntax error near over, window function needs an over clause, nth_value(integer, bigint) doesn't exists. Query works if I just uses something like

nth_value(v2,1) but I can't find how I can replace "1" with the current row position in the partition (1,2,3…)

 

I tried dozen of syntax with no success. Here is one of them

 

select roads,orders,(first_value(v1) over (partition by roads,segment order by orders)-(nth_value(v2,(cast(row_number() as integer)  over (partition by roads,segments order by orders))) over (partition by roads,segments order by orders)))  as result from my table

 

Thanks for any help !

 

Olivier

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

Предыдущее
От: Iuri Sampaio
Дата:
Сообщение: Re: Ajuda - insert into select com variavel
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: nth_value and row_number in a partition