X和Y之间的teradata Z对比Z = = Y且Z <1。 X

时间:2017-06-01 17:19:42

标签: sql teradata

我想在case语句中使用等号而不是between运算符,但是我得到语法错误

case 
when item_price between 5 and 6 then '5-6'
when item_price between 6 and 7 then '6-7
end as price_group

但是我知道这会在6个项目价格之间产生某种重叠,所以我更愿意使用

case 
when item_price >= 5 and item_price < 6 then '5-6'
when item_price >= 6 and item_price < 7 then '6-7
end as price_group

第二个查询给出了错误:

SELECT Failed 3706: Syntax error: expected something between '<' and '='.

1 个答案:

答案 0 :(得分:2)

无需每次检查范围,只需更高范围的范围

case 
when item_price <= 5 then '...-5'
when item_price <= 6 then '5-6'
when item_price <= 7 then '6-7'
else                      '7-...'
end as price_group