Advanced Select
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.
SELECT
CASE
WHEN A+B<=C OR A+C<=C OR B+C<=A THEN 'Not A Triangle'
WHEN A=B AND B=C AND A=C THEN 'Equilateral'
WHEN A=B OR B=C OR A=C THEN 'Isosceles'
ELSE 'Scalene'
END
FROM TRIANGLES;
SQL์์์ ๋ถ๊ธฐ๋ฌธ์ ์น๋ ๋ฐฉ๋ฒ์
CASE, WHEN-THEN, ELSE, END
WHEN์๋ ์กฐ๊ฑด๊ฐ์, THEN์๋ ๊ฒฐ๊ณผ๊ฐ์ ๋ฃ์ด์ฃผ๋ฉด๋๋๋ฐ, ๋ฆฌํด๊ฐ์๋ null๊ฐ์ด ๋ค์ด๊ฐ ์ ์๋ค๋ ์ ๊ธฐ์ต
๊ธฐ๋ณธ์ ์ผ๋ก if-else์ ๋ฐฉ์์ด๋ผ๊ณ ์๊ฐํ๋๋ฐ, switch๋ฌธ ์ฒ๋ผ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด
CASE ๋ค์ switch์์ ๊ฒ์ฌํ ํญ๋ชฉ์ด ๋ฌด์์ธ์ง ์ ์ด์ฃผ๊ณ , WHEN์๋ ๊ทธ๋ฅ ํญ๋ชฉ์ ๋ํ ๊ฐ์ ์ ์ด์ฃผ๋ฉด ๋๋ค
The PADS
https://www.hackerrank.com/challenges/the-pads/problem?isFullScreen=true&h_r=next-challenge&h_v=zen
๋ญ๊ฐ ์์ด๋ฅผ ๋๋ฌด ์ผ๋ผ์ผ๋ผ ์ฌ์... ๋ฒ์ญ๊ธฐ๋ฅผ ์ฌ์ฉํด์ ์งํ
OCCUPATIONS์ ๋ชจ๋ ์ด๋ฆ์ ์ํ๋ฒณ ์์ผ๋ก ๋์ดํ๊ณ , ๋์ดํ ๋ ๊ฐ ์ง์ ์ ์ฒซ ๊ธ์๋ฅผ ๊ดํธ๋ก ๋ฌถ์ด์ ์ถ๋ ฅํ๋ผ
OCCUPATIONS์์ ๋์จ ๊ฐ ์ง์ ์ ๊ฐฏ์๋ฅผ 'There are a total of [์ซ์] [์ง์ ]s' ์ด ํฌ๋งท์ผ๋ก ์ถ๋ ฅํ๋ผ
SELECT NAME || '(' || SUBSTR(OCCUPATION, 1, 1) || ')'
FROM OCCUPATIONS
ORDER BY NAME;
SELECT 'There are a total of ' || COUNT(OCCUPATION) || ' ' || LOWER(OCCUPATION) || 's.'
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY COUNT(NAME), OCCUPATION;
๋งํ๋ ๋ถ๋ถ์ SELECT ๋ฌธ์์ ๋ฌธ์์ด์ ๋ํ๋ ๊ฒ์ด์๋๋ฐ...
SQL์์๋ ๋ฌธ์์ด + ์ ||๋ก ํํํ๋ค๋ ๊ฒ์ ์๊ฒ๋์๋ค...!
COUNT, UPPER, LOWER, SUBSTR๋ ๊ธฐ์กด์ ํ๋๊ฒ ๊ธฐ์ต๋๋๋ผ
Last updated
Was this helpful?