博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql中case when then 语句
阅读量:4290 次
发布时间:2019-05-27

本文共 376 字,大约阅读时间需要 1 分钟。

在使用mysql数据库查表数据时,经常会有各种状态,有的时候一张表中有多个状态,使用下面的

case 字段

when  表中值  then 页面展示的提示

when  表中值  then 页面展示的提示

else 页面展示提示

end

语句可以很好的解决状态字段的页面展示问题

从表table中查询用户名username和付款状态payStatus,表中的payStatus 是使用数字1,2来表示的,展示时需要变为对应的未缴费和已缴费的汉字提示

当性别payStatus 字段是1时显示已缴费,2时显示未缴费,否则是信息错误

select

userName ,

( case payStatus when 1 then '已缴费' when 2 then '未缴费' else '信息错误' end) as payName

from table

查询结果:

你可能感兴趣的文章
Ubuntu16.04运行清空文件命令时提示权限不够解决方法
查看>>
shell脚本编写笔记
查看>>
Ubuntu16.04实现定时免密远程拷贝脚本
查看>>
Ubuntu 16.04安装Docker
查看>>
Docker报错:Temporary failure in name resolution&Proxy Authentication Required
查看>>
mySQL常用操作及基础知识
查看>>
Ubuntu16.04安装python3.6
查看>>
linux安装Anaconda
查看>>
Ubunu16.04安装CPU版本Tensorflow
查看>>
conda常用命令和基础知识整理
查看>>
ImportError: libgfortran.so.4: cannot open shared object file: No such file or directory
查看>>
Django搭建网站笔记
查看>>
不抱怨的世界
查看>>
运动减肥篇
查看>>
自己测到的Buu IP
查看>>
yum配置与使用(很详细)
查看>>
yum的使用
查看>>
./configure 的配置和用法
查看>>
web.config
查看>>
web.xml
查看>>