sql - How to look for changes in a table that keeps historical data? -


example:

field_1 | date x | 2010-01-01 x | 2010-02-01 x | 2010-03-01 y | 2010-04-01 y | 2010-05-01 y | 2010-05-01 

i select return following: (a change occurred in field_1) y | 2010-04-01

is there easy way this?

writen mssql:

declare @t table(field varchar(20), date date)  insert @t values('x', '2010-01-01') insert @t values('x', '2010-01-02') insert @t values('x', '2010-01-03') insert @t values('y', '2010-01-04') insert @t values('y', '2010-01-05') insert @t values('y', '2010-01-06')   select b.* @t join @t b on dateadd(day, 1, a.date) = b.date , a.field <> b.field 

result:

field                date -------------------- ---------- y                    2010-01-04 

it should work sybase if replace @t table , ignore test data


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -