开发者

Is there a function identical to "IF" but defaults the 3rd argument to NULL?

开发者 https://www.devze.com 2023-03-15 04:10 出处:网络
Basically I want to do IF(x>y,z,NULL) 开发者_开发技巧But without having to specify the 3rd argument all the time. I\'m going to be using this a lot and I want my queries to be a bit more readabl

Basically I want to do

IF(x>y,z,NULL)

开发者_开发技巧But without having to specify the 3rd argument all the time. I'm going to be using this a lot and I want my queries to be a bit more readable. Is there a function that is basically identical to IF except the 3rd argument defaults to NULL?


SELECT CASE x WHEN 'y' THEN NULL ELSE x END

something like this?


there's this. but it is a bit more specific than what you asked for...

IFNULL(foo, 123)

it means this

IF(foo IS NULL, 123, foo)


There does exist a NULLIF function, but its semantics are a bit different -- depending on the actual expressions x and y it might or might not work for you.

NULLIF (a, b)

returns a if a != b, and null if a = b.


No. There is no function that meets your requirements.

I'm answering myself because no one wrote "no" in their answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号