0
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

该表存在。字段存在。但是这些都用红色下划线:< BETWEEN AND

有谁知道我做错了什么?

4

1 回答 1

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

这显然对整数更有效。

于 2012-11-30T13:44:14.317 回答