I'd like to get the max integer from a specific column excluding a value that will always be the max if present. Data may look like the following:
score, empid
1 3
3 3
10 3
1 5
2 5
1 8
2 8
3 8
10 8
In the above, I'd like MAX score less than 10. MAX(score) doesn't work in this case since it will bring back 10. Results should look like this:
score, empid
3 3
2 5
3 8
Any suggestions?
Here's an alternative method:
SELECT
MAX(CASE WHEN score = 10 THEN NULL ELSE score END) AS [max_score],
empid
FROM
table
GROUP BY
empid
This may be preferable if you prefer to avoid the sub-select.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With