我正在做一个 pokemon sql 表并创建了一个名为 capacity_difference 的新列来确定表中每个 pokemon 的可收集性。但是,当我想使用 CASE 查询对它们进行分类时,结果只显示每个日志的 ELSE 条件。有人可以告诉我如何修复查询吗?
我的查询如下:
ALTER TABLE pokemon add capacity_difference INTEGER;
SELECT name, type_1, type_2, HP, (attack - defense) as capacity_difference from pokemon;
SELECT name, type_1, type_2, HP, (attack - defense) as capacity_difference,
CASE
when capacity_difference > 90 then "collect asap"
when capacity_difference < 90 and capacity_difference > 50 then "good"
when capacity_difference > 0 and capacity_difference < 50 then "okay"
when capacity_difference > -10 and capacity_difference < 0 then "bad"
ELSE "worse"
END AS Collectability
FROM pokemon;
问题是在评估您的案例表达式时,不知道重命名((攻击 - 防御)为 capacity_difference )。即您的案例表达式正在评估
capacity_difference
您尚未分配值的列。我建议您摆脱该列,并执行以下操作:使用 mysql 和 mariadb,你可以做到
db<>在这里摆弄