sql server - SQL - select all rows containing account number proceeding an earlier status -
when account reaches specific status, need return account number using select statement returning rows later date same account regardless of proceeding status. table , results bit this:table , expected results
if break down result set account number need this. account 001 first time see b2 want see later rows regardless of status, earlier rows ignored. have used example because b2 seen again later. rows 2,3,4 returned.
for account 002, there 1 row displayed. row 5 returned:
for account 003 b2 first given status no previous rows exclude. rows 6,7,8 returned.
select * yourtable t date_time >= (select min(date_time) yourtable p t.account_number = p.account_number , p.status = 'b2')
i think should trick, clause filters account numbers have status b2 , dates after it.
Comments
Post a Comment