现有这样一张学生表,学生的性别是布尔值,但是查询结果想要显示为男女
,而不是01
,该如何写查询语句?
- 查询学生性别,将数据库中的01显示为男女
使用case函数,使用方式:
case 列名 when 值1 then 显示1 when 值2 then 显示2 else 显示3 end
select stuname as 姓名,case stusex when 1 then '男' when 0 then '女' else '未知'
现有这样一张学生表,学生的性别是布尔值,但是查询结果想要显示为男女
,而不是01
,该如何写查询语句?
case 列名 when 值1 then 显示1 when 值2 then 显示2 else 显示3 end
select stuname as 姓名,case stusex when 1 then '男' when 0 then '女' else '未知'