1
capacity  Comment

1.0
1.7
7.2
9.9
10.0

what i want to do is, i want to auto full comment value based on capacity value.

if capacity value is 1, 1.2, 1.3, 1.4, 1.5.... (all decimals up to 1.9) i want to fill comment values as "low"

so that it will look like this

capacity  Comment

1.0        low
1.7        low  
7.2        average
9.9        fine
INTEL      great

Hope you understand this. Thanks in advance.

4

2 回答 2

1

您可以使用CASE表达式来执行此操作:

UPDATE Tablename
SET Comment = CASE 
                WHEN capacity >= 1.0 AND Capacity <= 1.9 THEN 'low'
                WHEN ... THEN 'average' -- Put the condition for the average 
                ... 
              END;
  • 在每个子句中放入WHEN每个级别的条件。
  • 不要忘记该ELSE子句,因为NULL如果您没有定义它,它具有默认值。
于 2013-05-11T18:00:23.310 回答
0

将更新与如果可能?

像这样:

UPDATE table
SET comment = IF (capacity < 2, 'low', IF(capacity < 8, 'average').... )
于 2013-05-11T17:58:30.890 回答