Skip to content
Advertisement

SQL group by date of DateTime and select first and last value

I am grouping by the date part of a DateTime column using the CONVERT function selecting the MAX and MIN price value for that date. I would like to include the first and last price values for the group based on the full DateTime value.

The current query looks like this:

Is it possible to include the first and last price in this group with the smallest/largest full DateTime without using a subquery?

Advertisement

Answer

It is possible without a subquery, but at the expense of performance:

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