mysql - 满足条件时如何将列中的值替换为字符串
问题描述
我正在尝试用“hit”或“flop”替换列中的值 0 或 1
select (Box_office_revenue-Budget)>Budget as hit_flop
from movie_data
hit_flop hit_flop
0 flop
0 flop
0 flop
1 hit
1 hit
如何在不创建新列的情况下用文本替换值
另外,我想在 box_office_revenue/budget > 10 时获得“超级热门”
解决方案
select
Case when box_office_revenue/budget > 10 then 'Super Hit'
when (Box_office_revenue-Budget)>Budget then 'Hit'
else 'Flop' end as hit_flop
from movie_data
推荐阅读
- docker - 使用 Letsencrypt 的本地 Nginx 反向代理到 Docker 容器
- react-native - 网络请求在使用 fetch 反应本机时失败
- python - os.listdir() 列出数据文件但相应的断言失败
- c# - 使用 sonarqube 构建 csharp 项目时出现“IsTestFileByName 任务意外失败”错误
- node.js - 在 DialogFlow 中使用内联编辑器进行 http 请求调用
- ios - 对象引用未设置为 iOS 中的对象实例
- postgresql - 为重复多次的每个 ID 选择具有第二高值的行
- node.js - Node JS SQL 防止sql注入
- permissions - 谷歌驱动文件权限更新
- python - 拆分非常大的 Pandas 数据帧,替代 Numpy array_split