sql - Select all records that match criteria plus next record that does not match criteria -
i've got table has columns this:
id, description, pc, account, amount
i'm going looking 009 value in "pc" column, , each datum has sequentially-numbered unique id in "id" column. every datum 009 "pc" value have @ least 1 item following doesn't have "009" pc value.
is there way can write query that's real , similar fake code below? possible?
select table.id id, table.description description, table.pc pc ((table.pc = 009) or (whatever, long table.id-1's "pc" value = 009))
if know id
s sequential, can put logic in where
clause:
select t.id, t.description, t.pc pc table t t.pc = 009 or exists (select 1 table t2 t2.id = t.id - 1 , t2.pc = 009 ) order t.id;
Comments
Post a Comment