gpt4 book ai didi

mysql - 为什么我在 mySql 中使用 union 时得到 null 作为输出?

转载 作者:行者123 更新时间:2023-11-29 18:15:06 24 4
gpt4 key购买 nike

Equilateral: It's a triangle with sides of equal length.
Isosceles: It's a triangle with sides of equal length.
Scalene: It's a triangle with sides of differing lengths.
Not A Triangle: The given values of A, B, and C don't form a triangle.

A、B 和 C 是 TRIANGLES 表中的列名称

SQL 查询

(
SELECT distinct
CASE
when (a=b and a<>c)
or (b=c and a<>c)
or (a=c and a<>b)
then 'Isosceles'
end
from triangles
)
union
(
SELECT distinct
CASE
when a=b
and b=c
then 'Equilateral'
end
from triangles
)
union
(
SELECT distinct
CASE
when a!=b
and b!=c
and a!=c
then 'Scalene'
end
from triangles
)
union
(
SELECT distinct
CASE
when a+b<c
or b+c <a
or a+c<b
then 'Not A Triangle'
end
from triangles
);

输出

等腰

等边

斜角肌

不是三角形

最佳答案

你可以尝试:

SELECT distinct 
CASE
when (a=b and a<>c)
or (b=c and a<>c)
or (a=c and a<>b)
then 'Isosceles'
when a=b
and b=c
then 'Equilateral'
when a!=b
and b!=c
and a!=c
then 'Scalene'
else 'Not A Triangle'
end
from triangles

您可以根据需要更改条件。

关于mysql - 为什么我在 mySql 中使用 union 时得到 null 作为输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47088964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com