A MySQL IF condition
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
精彩评论