Skip to content
Advertisement

MS SQL return single row case dataset without GROUP BY clause

I have a data set of ActivityDate which is a datetime field and EngineHours which is a decimal field. I want to return a single row of data that brings back the average number of EngineHours on each day of the week. The dataset is pretty big so the best performance is likely to be the most ideal, the script below doesn’t work because ActivityDate is not contained in either an aggregate or GROUP BY clause:

Advertisement

Answer

Close. The CASE is the argument to the AVG():

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