5
Answers

Comparing Data in Two Consecutive Rows in SQL Server

Rohatash Kumar

Rohatash Kumar

8y
3.9k
1
Suppose my database table is looks like below table,

Id               Name    Status

2012-07-16    A        Login
2012-07-16    A        Logout
2012-07-16    A        Login
2012-07-16    A        Login
2012-07-16    A        Logout

In the above table, Two consecutive rows have the same name login then only last row should be display in the output table. AND I want a output like that:

Date            Name     Status

2012-07-16    A          Login
2012-07-16    A          Logout
2012-07-16    A          Login
2012-07-16    A          Logout

How can I do this?  Please help me.

Answers (5)