A difficult SQL query
Posted on 2007-11-28
I have a table like following, it has three columns:
ID Status Date
1 13 3/8/2007 18:55:58
2 14 3/9/2007 19:00:00
3 13 3/10/2007 19:00:00
4 13 3/11/2007 19:00:00
I want to make a sql query to get the following record:
status 13 insert to table after status 14(base on date column), such as ID 3 record in above sample table.
and if the lastest record is not 14, like row 4, the lastest record is 13, so row 4 shouldn't be selected.
In sample table, only row 3 should be selected.
I am not sure I have explained it very clear, pls. help me. Thanks a lot!
btw, server is sql-server, so t-sql can be used.