Created
November 11, 2021 04:57
-
-
Save euclid1990/9a5c5d16eeeefdd7d52986e2d786dd2a to your computer and use it in GitHub Desktop.
Consider NULL as MAX in SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION IF EXISTS fconsider_null_as_max; | |
DELIMITER // | |
CREATE FUNCTION fconsider_null_as_max (originalYear INT) | |
RETURNS INT | |
BEGIN | |
RETURN CASE | |
WHEN MAX(originalYear IS NULL) = 0 THEN MAX(originalYear) | |
ELSE originalYear | |
END; | |
END; // | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment