简体   繁体   English

将mysql boolean返回为'yes'或'no'

[英]return mysql boolean as 'yes' or 'no'

I have a BOOLEAN type column in my table. 我的表中有一个BOOLEAN类型列。 I would like to convert the 0/1 to Yes/No when the results are returned. 我想在返回结果时将0/1转换为是/否。

I found a response on this thread: Echo boolean field as yes/no or other values 我在这个线程上找到了一个响应: Echo布尔字段为yes / no或其他值

The response mentioned an IF THEN statement, but when I try, I only get a complaint from MySQL that there is a syntax error. 响应提到了IF THEN语句,但是当我尝试时,我只收到来自MySQL的抱怨语法错误。 Here is the line I am using: 这是我正在使用的行:

IF qz.quiz_enabled == 1 THEN 'yes' ELSE 'no' AS enabled

Here is the error: 这是错误:

use near 'qz.quiz_enabled == 1 THEN 'yes' ELSE 'no' AS enabled
select case when qz.quiz_enabled 
            then 'yes' 
            else 'no' 
       end

or 要么

select if(qz.quiz_enabled, 'yes', 'no')

SQLFiddle demo SQLFiddle演示

http://dev.mysql.com/doc/refman/5.0/en/if.html http://dev.mysql.com/doc/refman/5.0/en/if.html

BEGIN
DECLARE s VARCHAR(20);

IF n > m THEN SET s = '>';
ELSEIF n = m THEN SET s = '=';
ELSE SET s = '<';
END IF;

SET s = CONCAT(n, ' ', s, ' ', m);

RETURN s;
END 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM