原题

A pupil Tim gets homework to identify whether three line segments could possibly form a triangle.
However, this assignment is very heavy because there are hundreds of records to calculate.
Could you help Tim by writing a query to judge whether these three sides can form a triangle, assuming table triangle holds the length of the three sides x, y and z.

x y z
13 15 30
10 20 15
For the sample data above, your query should return the follow result:
x y z
---- ---- ----
13 15 30
10 20 15

解析

给一组xyz,代表三角形的三边
写sql输出,判断三边是否能组成三角形

思路

我的思路本是想判断三边中最长的边是不是大于其余两边之和,但是太麻烦,可以直接三边都判断

解法

SELECT 
    x,
    y,
    z,
    CASE
        WHEN x + y > z AND x + z > y AND y + z > x THEN 'Yes'
        ELSE 'No'
    END AS 'triangle'
FROM
    triangle
;

相关文章:

  • 2022-03-07
  • 2022-01-18
  • 2021-11-25
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2021-07-09
  • 2022-03-02
  • 2022-01-31
  • 2021-08-02
  • 2021-12-22
相关资源
相似解决方案