SQL Server Comparing Subsequent Rows for Duplicates -
I am trying to write a SQL server query, but there was no luck and wondering how anyone Any idea may be get my query.
What I'm trying to do:
I have several column tables whose names I am working with TaskID, StatusCode, Timestamp. Now in this table, the work for one of our systems has been completed, which runs throughout the day and when some runs are done, then the timestamp and the status of the work is done based on the situation.
Sometimes whatever happens, the work table can be updated with a new timestamp, but the status code will not change after the last update of the work so that two or more consecutive tasks The status code for rows can be the same. When I say that consecutive rows are meant in relation to the timestamp.
For example, there may be twenty rows on position 2 in position 88, after which the status code turns into something else.
Now I'm trying with no luck in that destiny, he is to receive a list of all functions and Stetsods and timestamp, but in a situation where I have more than one row Rows To work with the same stats, I want to take the first line with the least timestamp and want to ignore the rest of the row to change the status I received.
In this case it's easy to make the value I'm a taskid which I'm filtering on so I'm just looking at the same job.
Anyone have any ideas as to how I can coudl this or maybe something that I probably read to help?
Thank you Irfan.
There are a few ways to do this:
SELECT T1.task_id, T1.status_code, T1.status_timestamp from My_Table T1 Connect on left My_Table T2 ON T2.task_id = T1.task_id and T2.status_timestamp & lt; T1.status_timestamp LEFT OUTER My_Table T3 ON T3.task_id = T1.task_id and T3.status_timestamp & lt; T1.status_timestamp and T3.status_timestamp & gt; T2.status_timestamp where T3.task_id zero and (T2.status_code tap or T2.status_code & lt; & gt; T1.status_code) Order
or
(My_table maximum (status_timestamp) from T3 select where T3. task_id = T1.task_id and T3.status_timestamp & LT; T1.status_timestamp) where (T2.status_code tap or T2.status_code & lt; & gt; T1.status_code) order Fill in both ways there is going to be an exact match status_timestamp values Interpretation do (two lines may not be the exact same status_timestamp for task_id given.)
Comments
Post a Comment