Skip to content
Advertisement

SQL Query to Select Min and Max Values For Each Day Over a Period

I would like to select all the rows that contain either min or max datetime values for each equipment_id, for every day included in the period.

The code below selects the min and max datetime values for each equipment_id over the entire period. What can/should I change to reach desired select results?

Note: the values enclosed in braces in the code snippet represent dynamic values.

Advertisement

Answer

Use window functions:

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