Tuesday, October 15, 2019

Account for nulls in MIN and MAX operations in T-SQL.

SELECT
foo,
CASE WHEN MAX(CASE WHEN bar IS NULL THEN 0 ELSE bar END)=1 THEN 1 ELSE 0 END as bar
FROM baz
GROUP BY foo
HAVING qux > 42

No comments:

Post a Comment