我想按价格值设置object_type Elite,Premium或Regular,我如何更新数据库中的object_type列?
我的SQL请求如下:
select price_per_m2,
(
CASE
WHEN price_per_m2 > 500000 THEN 'Elite'
WHEN price_per_m2 > 200000 && price_per_m2 < 499999 THEN 'Premium'
ELSE 'Regular'
END) AS object_type
from new_housing;
答案 0 :(得分:1)
尝试以下查询:
UPDATE new_housing
SET object_type = CASE WHEN price_per_m2 > 500000 THEN 'Elite'
WHEN price_per_m2 > 200000 && price_per_m2 < 499999 THEN 'Premium'
ELSE 'Regular' END
WHERE <some condition>;
答案 1 :(得分:0)
有条件
UPDATE new_housing
SET object_type = CASE WHEN price_per_m2 > 500000 THEN 'Elite'
WHEN price_per_m2 > 200000 && price_per_m2 < 499999 THEN 'Premium'
ELSE 'Regular' END
WHERE price_per_m2;