I know that coalesce will return the first non-null value that is passed to it. is there something simlilar that will return the first not empty / not false value?
example:
select FunctionIWant(0,'','banana') as fruit; //returns banana.
解决方案SELECT CASE
WHEN LENGTH(col) = 0 OR col IS NULL THEN 'banana'
ELSE col
END AS fruit
There's no boolean in SQL, or MySQL. MySQL actually stores the value as an INT, values zero or one:
SELECT CASE
WHEN col = 0 THEN 'banana'
ELSE col
END AS fruit