일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 그로스해킹
- SQL
- having
- solvesql
- matplotlib
- TRUNCATE
- mysql :=
- Round
- 결측값
- 파이썬
- 데이터시각화
- PostgreSQL
- 머신러닝
- 전처리
- pandas
- GROUPBY
- 다중 JOIN
- seaborn
- airflow 설치
- join
- not in
- 프로그래머스
- 데이터리안 웨비나
- SUM
- SQLite
- Limit
- hackerrank
- MySQL
- Oracle
- 데이터분석
Archives
- Today
- Total
Milky's note
[HackerRank](E) Type of Triangle 본문
https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true
[문제]
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:
- 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.
- Not A Triangle: The given values of A, B, and C don't form a triangle.
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.
[답]
-mysql
SELECT
CASE
WHEN A=B AND A=C AND B=C THEN 'Equilateral'
WHEN A>=B+C OR B>=A+C OR C>=A+B THEN 'Not A Triangle'
WHEN A=B OR A=C OR B=C THEN 'Isosceles'
ELSE 'Scalene' END
FROM TRIANGLES;
이 문제는 case when 문으로 해결하면 된다.
case 문의 문법은
case
when 조건 then '출력'
else '출력' end
이므로, 삼각형의 해당되는 조건을 입력해준 뒤, 맞는 삼각형을 출력한다.
'SQL > SQL 코딩 테스트-HackerRank' 카테고리의 다른 글
[HackerRank](M) Binary Tree Nodes (0) | 2022.03.18 |
---|---|
[HackerRank](M) The PADS (0) | 2022.03.18 |
[HackerRank](E) Employee Salaries (0) | 2022.03.18 |
[HackerRank](E) Employee Names (0) | 2022.03.18 |
[HackerRank](E) Higher Than 75 Marks (0) | 2022.03.18 |
Comments