首页 > 解决方案 > 比较 SQL 案例语句中的 3 个变量

问题描述

我正在比较表中的 3 个变量值,因为我正在使用 case 语句。

这是桌子的图像。

在此处输入图像描述

我正在尝试的是这个 SQL 选择查询。

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;

我得到的错误如下图所示。

在此处输入图像描述

谁能指导我做错了什么?

标签: sqlsql-server

解决方案


重写你的表达式,这是不支持的。

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;

推荐阅读