Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据MYSQL中其他字段的结果添加新列的查询_Mysql_Sql - Fatal编程技术网

根据MYSQL中其他字段的结果添加新列的查询

根据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

目前我有一张桌子

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
          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且支出金额