这是我的ER图
我想将business
表中的business
属性分类为如下所示:
我试过使用以下代码:
select case b.stars
when (b.stars >= 2.0 and b.stars <=3.0) then '2-3'
when (b.stars >= 4.0) then '4-5'
else 'none'
end stars_group
from business b
但是当这个表不起作用的情况下,如何解决这个问题呢?
发布于 2020-07-17 12:17:23
你混淆了这两种情况。您需要具有不同条件的版本:
select (case when (b.stars >= 2.0 and b.stars <= 3.0) then '2-3'
when (b.stars >= 4.0) then '4-5'
else 'none'
end) as stars_group
如果您只是使用相等,则可以使用一个简单的大小写表达式--但是比较需要严格相等:
select (case trunc(b.stars)
when 2 then 'Two'
when 3 then 'Three'
else 'none'
end) as stars_group
使用不等式时,需要搜索每个where
子句以确定返回的第一个then
。所搜索的病例在case
和where
之间没有表达。
https://stackoverflow.com/questions/62953777
复制相似问题