首页 > 解决方案 > 满足条件时如何将列中的值替换为字符串

问题描述

我正在尝试用“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 时获得“超级热门”

标签: mysqldatabase

解决方案


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

推荐阅读