返回mysql布尔值'是'或'否' [英] return mysql boolean as 'yes' or 'no'

查看:235
本文介绍了返回mysql布尔值'是'或'否'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表中有一个BOOLEAN类型的列.返回结果时,我想将0/1转换为Yes/No.

I have a BOOLEAN type column in my table. I would like to convert the 0/1 to Yes/No when the results are returned.

我在此线程上找到响应: Echo布尔字段为是/否或其他值

I found a response on this thread: Echo boolean field as yes/no or other values

响应中提到了IF THEN语句,但是当我尝试时,我只收到MySQL的抱怨,说它存在语法错误.这是我正在使用的行:

The response mentioned an IF THEN statement, but when I try, I only get a complaint from MySQL that there is a syntax error. Here is the line I am using:

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

这是错误:

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

推荐答案

select case when qz.quiz_enabled 
            then 'yes' 
            else 'no' 
       end

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

这篇关于返回mysql布尔值'是'或'否'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆