postgresql - excluding rows from resultset in postgres -
this result set
i returning result set on base of refid
using where refid in
. on here, need apply logic without kind of programming (means sql query only).
if in result set, getting period
particular refid
other rows same refid
must not returned.
for example, 2667105 having period
myid
= 612084598 must not returned in result set.
according me can achieved using case have no idea how use it, mean don't know should use case
statement in select
statement or where
clause...
edit:
this how suppose work,
myid
= 612084598 default row refid
= 2667105 if wants refid
period
= 6 must return rows except myid
= 612084598
but if looking period
= 12, period
no specific refid
present in database.. must return rows except first one.. means rows refid
default one..
not clear definition of problem, try this:
with cte ( select *, first_value(period) over(partition refid order myid) fv test ) select myid, refid, period cte period not null or fv null
Comments
Post a Comment