0

I have a table with many rows that stores changes of a table.

Example:

Column A - Column B - Date

1) 0 - 0 - Sept 1st 12 PM
2) 0 - 1 - Sept 2nd 1 PM
3) 0 - 2 - Sept 2nd 2 PM
4) 1 - 0 - Sept 2nd 5 PM
5) 1 - 1 - Sept 3rd 1 PM
6) 0 - 1 - Sept 3rd 2 PM
.
.
.

I would like to create a select query in which:

Column A has just changed and the value has become specifically "1", when sorted by Date.

I want the select query to return only row 4 from the rows visible above.

In my case, I would like to bring all rows that are similar to row 4 in this example. How do I do that?

Alexander
  • 69
  • 7
  • Your question isn't clear to me. Why do you want to only show row 4? The last change would be row 6 - Sept 3rd 2 PM where column A changed from 1 to 0? – Carra Nov 15 '21 at 14:11
  • *"I want the select query to return only row 4 from the rows visible above."* Does this answer your question? [How to select the nth row in a SQL database table?](https://stackoverflow.com/questions/16568/how-to-select-the-nth-row-in-a-sql-database-table) – Thom A Nov 15 '21 at 14:11
  • As stated in the post, I want the query to return rows in which in Column A the value has just changed and specifically it has become "1", when the data is sorted by Date. I don't want it to return all the rows in which the value changes. – Alexander Nov 15 '21 at 14:16
  • In the example you gave me, it displays two rows, where it's similar to a select query with a WHERE Column A = 1. – Alexander Nov 15 '21 at 14:22
  • Take a look at LEAD/LAG. And hopefully your actual data you have a datetime and not these strings which would never work properly for ordering. – Sean Lange Nov 15 '21 at 16:47

0 Answers0