sql - get the previous row of a query -
doing select row, , want previous row in table.
create table t1 id char(3), dat datetime ); id dat 2014-04-21 b 2014-10-01 c 2014-10-15 select id t1 id='c'
and wanted find previous row i.e. b
what about:
declare @id char(3) set @id = 'c' select id table id=@id or id = (select max(id) table id < @id)
sql sql-server select
No comments:
Post a Comment