-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path610-TriangleJudgement.sql
More file actions
48 lines (45 loc) · 1.45 KB
/
610-TriangleJudgement.sql
File metadata and controls
48 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- 610. Triangle Judgement
-- Table: Triangle
-- +-------------+------+
-- | Column Name | Type |
-- +-------------+------+
-- | x | int |
-- | y | int |
-- | z | int |
-- +-------------+------+
-- (x, y, z) is the primary key column for this table.
-- Each row of this table contains the lengths of three line segments.
--
-- Write an SQL query to report for every three line segments whether they can form a triangle.
-- Return the result table in any order.
-- The query result format is in the following example.
-- Example 1:
-- Input:
-- Triangle table:
-- +----+----+----+
-- | x | y | z |
-- +----+----+----+
-- | 13 | 15 | 30 |
-- | 10 | 20 | 15 |
-- +----+----+----+
-- Output:
-- +----+----+----+----------+
-- | x | y | z | triangle |
-- +----+----+----+----------+
-- | 13 | 15 | 30 | No |
-- | 10 | 20 | 15 | Yes |
-- +----+----+----+----------+
-- Create table If Not Exists Triangle (x int, y int, z int)
-- Truncate table Triangle
-- insert into Triangle (x, y, z) values ('13', '15', '30')
-- insert into Triangle (x, y, z) values ('10', '20', '15')
-- 三角形三边关系是三角形三条边关系的定则,具体内容是在一个三角形中,任意两边之和大于第三边,任意两边之差小于第三边。”
-- Write your MySQL query statement below
SELECT
*,
CASE
WHEN x + y > z AND x + z > y AND y + z > x THEN 'Yes'
ELSE 'No'
END AS `triangle`
FROM
`triangle`