根据MYSQL中其他字段的结果添加新列的查询
目前我有一张桌子 id amount_spend 1 10 2 20 3 30 4 40 5 50 你花了多少钱 1 10 2 20 3 30 4 40 5 50 我想添加第三列,名为根据MYSQL中其他字段的结果添加新列的查询,mysql,sql,Mysql,Sql,目前我有一张桌子 id amount_spend 1 10 2 20 3 30 4 40 5 50 你花了多少钱 1 10 2 20 3 30 4 40 5 50 我想添加第三列,名为category,它应该显示: 高(如果支出金额>30) 中等(支出金额>20和20) 请告诉我如何将其添加到select语句中。select id, select id, amount_spend, case whe
category
,它应该显示:
- 高(如果支出金额>30)
- 中等(支出金额>20和20)
select id,
select id,
amount_spend,
case
when amount_spend > 30 then 'high'
when amount_spend > 20 and amount_spend <= 30 then 'medium'
else 'low'
as category
from the_table;
你的花费,
案例
当支出金额>30时,则为“高”
当支出金额>20且支出金额