postgresql - Group by id dependent less time at postgres sql -


i have table structure @ postgres db :

id | item | name  | time 1  |    | shoes | 01 1  | b    | hat   | 02 2  | c    | shirt | 01 2  | d    | glove | 02 

i need transfor table :

prev_item | item | name         | b    | hat c         | d    | glove 

it's based on time, time less should prev_item each id

how sql ?

thx

use row_number & lag window function

select * ( select row_number()over(partition id order time desc) rn,        lag(item) over(partition id order time) prev_item,* yourtable ) rn = 1 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -