本文介绍了MYSQL中的三角形类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题陈述:
- 不是三角形:A,B和C的给定值不会形成三角形.
- 等边:这是一个边长相等的三角形.
- 等腰线:这是一个边长相等的三角形.
- Scalene:这是一个三角形,其边长不同.输入格式
- Not A Triangle: The given values of A, B, and C don't form a triangle.
- 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. Input Format
TRIANGLES表描述如下:
The TRIANGLES table is described as follows:
表中的每一行表示每个三角形的长度 三个方面.
Each row in the table denotes the lengths of each of a triangle's three sides.
Sample Input
------------
A B C
20 20 23
20 20 20
20 21 22
13 14 30
Sample Output
-------------
Isosceles
Equilateral
Scalene
Not A Triangle
尝试失败:
select
case
when A+B < C or A+C < B or B+C < A then "Not A Triangle"
when A=B and B=C then "Equilateral"
when A=B or A=C or B=C then "Isosceles"
when A<>B and B<>C then "Scalene"
end as triangles_type
from TRIANGLES;
推荐答案
SELECT
CASE
WHEN A + B <= C or A + C <= B or B + C <= A THEN 'Not A Triangle'
WHEN A = B and B = C THEN 'Equilateral'
WHEN A = B or A = C or B = C THEN 'Isosceles'
WHEN A <> B and B <> C THEN 'Scalene'
END tuple
FROM TRIANGLES;
- 使用case语句检查给定的输入是否为三角形.
- 如果它是一个三角形,那么如果 true 三角形类型为等边",则检查所有边是否都相同.
- 如果不是,则检查三角形的类型为等腰"的情况下,两个边是否相等?
- 在不相等的情况下,三角形的任意边均为"Scalene".我们也可以直接使用 ELSE .
- By using case statement check if given input is a triangle or not.
- If it is a triangle then check if all sides are same if true the triangle type is 'Equilateral'.
- If not then check if any two sides are equal if true the triangle type is 'Isosceles'
- In the case of not equal, any sides the triangle type is 'Scalene'. We can directly use ELSE also.
这篇关于MYSQL中的三角形类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!