Skip to content
Advertisement

Selecting first and last time stamps of a section

I have a MySQL database with a table like:

I would like to select from this table the first and last timestamp for each value of each Batch_Number. I would like the table to look like:

I am not sure how to select both, when the previous Batch_Num is different from the curent one, and also when the next one is different.

Advertisement

Answer

A basic GROUP BY query should work here:

screen capture from demo link below

Demo

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement