执行mysql出来三角号_MYSQL中的三角形类型

bd96500e110b49cbb3cd949968f18be7.png

Problem statement:

Write a query identifying the type of each record in the TRIANGLES

table using its three side lengths. Output one of the following

statements for each record in the table:

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

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

Attempt that did not work:

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;

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值