Skip to content
Advertisement

group by issue in sql

i’m trying to get in a new column the sessions who are between 08:00 and 18:00. You can see my last CASE in the CTE. For each date there should be a new column “TotalRestrictedSessions” which indicate how many session were on that particular date. If there are none, in this case i have to write 0. I suspect that my problem is when i convert the DATE?

Advertisement

Answer

You just need to move your aggregation outside of your CASE expression, called conditional aggregation.

Generally, you should include the current query results and your desired results in your question to make it easier to figure out where the issues are.

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