gpt4 book ai didi

mysql - sql列格式化

转载 作者:行者123 更新时间:2023-12-01 00:05:19 24 4
gpt4 key购买 nike

只是一个简单的问题要问

在 MySQL 中,我如何将数值显示为字符串等值?

所以

1 = New
2 = Old
3 = Cancelled

所以如果我有类似的东西

SELECT object_name, object_status where object_status > 0

然后返回

object#1, 1
object#2, 2
object#3, 1
object#4, 3

但我想让它显示

object#1, New
object#2, Old
object#3, New
object#4, Cancelled

提前致谢KS

最佳答案

你可以在这上面使用CASE

SELECT object_name,         
CASE object_status
WHEN 1 THEN 'New'
WHEN 2 THEN 'Old'
WHEN 3 THEN 'Cancelled'
ELSE NULL
END status
where object_status > 0

SELECT object_name,         
CASE
WHEN object_status = 1 THEN 'New'
WHEN object_status = 2 THEN 'Old'
WHEN object_status = 3 THEN 'Cancelled'
ELSE NULL
END status
where object_status > 0

关于mysql - sql列格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14776045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com