Skip to content
Advertisement

Trying to find the max observation by group

I have the below code where I am trying to find a patients injury level and whether it is between 1 and 5 or 6 and 10. I have used the ‘case when’ clause below. The issue is, some patients have multiple injury levels. Is there a way for me to only get the max injury level and ignore the others?

Advertisement

Answer

Assuming that you want the max injury level per patient and date:

When you group, a column must either be listed in the GROUP BY clause or you must apply an aggregate function to it like MIN, MAX, SUM, etc.

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