Red Glitter Pointer

 

https://www.hackerrank.com/challenges/african-cities/problem?isFullScreen=true

 

African Cities | HackerRank

Query the names of all cities on the continent 'Africa'.

www.hackerrank.com

 

 

 

SELECT city.name
FROM city
    INNER JOIN country ON city.countrycode = country.code
WHERE country.continent = 'Africa'

 

 

 

Type of Triangle | HackerRank

Query a triangle's type based on its side lengths.

www.hackerrank.com

 

 

SELECT CASE
    WHEN A = B AND B = C THEN 'Equilateral'
    WHEN A + B <= C OR B + C <= A OR C + A <= B THEN 'Not A Triangle'
    WHEN A = B OR B = C OR A = C THEN 'Isosceles'
    ELSE 'Scalene'
    END
FROM triangles

 

느낀 점 및 정리 ✍️

1. 정삼각형인지 확인 후 Equilateral, 정삼각형이 아니라면 삼각형 조건에 부합하는지 먼저 확인한다. Not A Triangle

2. 삼각형 조건에 부합한다면 두 변의 길이가 같은지 판단, 같다면 Isosceles

3. 아니라면 세 변의 길이가 다 다른 것임 ! Scalene

4. 삼각형 조건에 충족되지 않는데 두 변의 길이가 같을 수 있기 때문에 두 변의 길이가 같은지 확인하기 전에 삼각형 조건 먼저 확인해줘야 함! 

 

 

 

 

Top Earners | HackerRank

Find the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount).

www.hackerrank.com

 

 

 

 

SELECT salary * months as earnings
    ,COUNT(*)
FROM employee
GROUP BY earnings
ORDER BY earnings DESC
LIMIT 1

 

 

느낀 점 및 정리 ✍️

1. maximum total earnings => Max(salary * months)

2. total number of employees who have maximum total earnings => GROUP BY earnings , COUNT(*)

 

 

 

 

Revising Aggregations - Averages | HackerRank

Query the average population of all cities in the District of California.

www.hackerrank.com

 

 

SELECT AVG(population)
FROM city
WHERE district = 'California'

 

 

 

 

 

SELECT ROUND(long_w, 4)
FROM station
WHERE lat_n < 137.2345
ORDER BY lat_n DESC
LIMIT 1

 

 

느낀 점 및 정리✍️

1. largest Northern Latitude 중에 가장 큰 값 => DESC 정렬하여 LIMIT 1로 구했다

2. 137.2345보다 작은 값이어야하기 때문에 => WHERE절 사용하여 걸러냄

3. 소수점 4자리까지 반올림 한 값을 출력 => ROUND 사용

 

 

 

 

 

 

 

SELECT name
FROM students
WHERE marks > 75
ORDER BY RIGHT(name, 3), id

 

 

느낀 점 및 정리 ✍️

1. "Order your output by the last three characters of each name" => RIGHT(name, 3) 을 사용해서 이름의 가장 오른쪽에 있는 문자 3개를 추출하여 정렬했다.

2. "names ending in the same last three characters, secondary sort them by ascending ID" => 문자 3가지가 동일할 경우 id 오름차순 정렬

 

 

 

 

+ Recent posts

loading