postgresql - How to get info about position element in the table? -


i have query:

select * mytable order 'date' 

and result:

   date    | item_id | user_id | some_data ------------------------------------------ 2015-01-01 |       1 |       1 | null 2015-01-01 |       1 |       1 | null 2015-01-02 |       1 |       1 | null 2015-01-03 |       1 |       1 | null 2015-01-03 |       1 |       2 | null 2015-01-04 |       1 |       1 | null 2015-01-05 |       1 |       2 | null 

and want position of first row user_id = 2. in example 5. how it?

select pos_overall (   select user_id,           row_number() on (order "date") pos_overall,          row_number() on (partition user_id order "date") user_pos   mytable ) t user_id = 2   , user_pos = 1 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -