I need help to be able to do the following:
MainTable has
ID (Primary Key)
DATE_TIME
STATE
SubTable has
ID (Primary Key)
DATE_TIME
LINE1
When MainTable.STATE
value changes from 100 to 200, I want to select SubTable.Line1
value where MainTable.DATE_TIME = SubTable.DATE_TIME
It seems that either LAG()
or LEAD()
function can detects this transition of data in MainTable.STATE
field.
How can do this with SQL statement using LAG()
or LEAD()
function?
Thanks for all the quick responses. Since MainTable.STATE value could be anything, I can't include its value in the sql stmt.
Here is a solution: