2017-03-19 87 views
-1

我想設置object_type精英,高級或常規的價格價值,我如何更新我的數據庫中的object_type列?MYSQL更新列在案例

我的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

隨着更新語句? – TZHX

+0

使用我所有項目的循環更新 –

回答

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; 
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>;