我正在使用case语句比较表中的3个变量值。
这是表格的图像。
我正在尝试的是这个SQL select查询。
select a,b,c,
case(
when (a=b=c) then "Equilateral"
when a!=b!=c then "Scalene"
when a=b!=c or a!=b=c then "Isosceles"
else "Not A Triangle"
end as Text
)
from TRIANGLES;
我收到的错误如下图所示。
有谁能指点我哪里做错了吗?
发布于 2019-11-21 15:20:01
重写您的表达式,这是不受支持的。
select a,b,c,
case
when (a=b) and (b=c) then 'Equilateral'
when (a!=b) and (b!=c) then 'Scalene'
when (a=b and b!=c) or (a!=b and b=c) then 'Isosceles'
else 'Not A Triangle'
end as [Text]
from triangles;
发布于 2019-11-21 15:18:36
您不能像a = b = c
那样链接比较,您需要显式地分别编写它们并合并它们的结果:
when (a = b AND a = c) then "Equilateral"
when (a != b AND b != c AND c != a) then "Scalene"
诸若此类。
发布于 2019-11-21 15:28:10
不能一次比较3个操作数。您需要使用and运算符对其进行拆分。
select a,b,c,
case(
when (a=b and b=c) then 'Equilateral'
when (a!=b and b!=c and c!=a) then 'Scalene'
when (a=b and b!=c) or (a!=b and b=c) then 'Isosceles'
else 'Not A Triangle'
end as Text
)
from TRIANGLES;
https://stackoverflow.com/questions/58969233
复制相似问题