开发者

A MySQL IF condition

开发者 https://www.devze.com 2022-12-08 20:59 出处:网络
In my query I have an IF statement: 开发者_高级运维IF(friend.block, \'yes\', \'no\') where friend.block value is 0 or 1.. but either way its putting \'yes\'.. any idea?friend.block should be of ty

In my query I have an IF statement:

开发者_高级运维IF(friend.block, 'yes', 'no') 

where friend.block value is 0 or 1.. but either way its putting 'yes'.. any idea?


friend.block should be of type INTEGER for that to work or you have to put a comparaison there:

IF(friend.block != 0, 'yes', 'no')


Reference: MySQL Reference

The syntax is:

IF (friend.block = 1) THEN
    'Yes'
ELSE
    'No'
END IF

You can use case statement:

CASE friend.block WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END


CASE friend.block WHEN 1 THEN 'yes' WHEN 0 THEN 'no' END
0

精彩评论

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