SELECT field1, field2,
Budget = CASE field2
WHEN field2> 20.00 THEN 'Expensive'
WHEN field2 BETWEEN 10.00 AND 19.99 THEN 'Moderate'
WHEN field2< 10.00 THEN 'Inexpensive'
ELSE 'Unknown'
END
FROM table1
该表存在。这些字段存在。但这些都用红色加下划线: &LT; 之间 和
有谁知道我做错了什么?
答案 0 :(得分:2)
删除“CASE”后面的第一个“field2”
SELECT field1, field2,
Budget = CASE
WHEN field2 > 20.00 THEN 'Expensive'
WHEN field2 BETWEEN 10.00 AND 19.99 THEN 'Moderate'
WHEN field2 < 10.00 THEN 'Inexpensive'
ELSE 'Unknown'
END
FROM table1
编辑:如果您的案例不变,您可以使用不同的语法。
SELECT field1, field2,
Budget = CASE field2
WHEN 20 THEN 'Expensive'
WHEN 15 THEN 'Moderate'
WHEN 10 THEN 'Inexpensive'
ELSE 'Unknown'
END
FROM table1
这显然对整数有效。