[Leetcode] 610. Triangle Judgement_easy Tag:sql

Source: Internet
Author: User

A pupil Tim gets homework to identify whether three line segments could possibly form a triangle.

However, this assignment is very heavy because there was hundreds of records to calculate.

Could writing a query to judge whether these three sides can form a triangle, assuming table triangle holds t He 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  | triangle | | ----|----|----|----------|| 13 | 15 | 30 | No       | | 10 | 20 | 15 | Yes      |

Code

1) Use IF

SELECT * ,  (x+y> and x+z> and y+Z >  as Triangle  from Triangle

2) Use case

SELECTx, Y, Z, Case         whenX+Y>Z andX+Z>Y andY+Z>X Then 'Yes'        ELSE 'No'    END  as 'Triangle' fromTriangle

[Leetcode] 610. Triangle Judgement_easy Tag:sql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.