sql - Detecting last row of a group -


i using row_number() determine last row of query creating descending order , checking if on position 1.

row | value ----+-------   3 | false   2 | false   1 | true 

do have idea how apply same technique determine last row of every group?

the expected result should this:

uid | row | value ----+-----+-------   1 |   3 | false   1 |   2 | false   1 |   1 | true   2 |   4 | false   2 |   3 | false   2 |   2 | false   2 |   1 | true   3 |   2 | false   3 |   1 | true 

or know better way detect last rows in postgresql?

use partition by part of over():

select uid,something,   row_number() on (partition uid order desc) row   sometable 

partition by causes whatever window function you're using (such row_number()) operate complete separately on each partition defined - row_number restarts number, max find maximum value rows within partition, etc.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -