[HackerRank] SQL Basic (easy)(3)

2025. 8. 13. 22:31·코딩 테스트/02. SQL

1. Higher Then 75 Marks

https://www.hackerrank.com/challenges/more-than-75-marks/problem?isFullScreen=true

 

Higher Than 75 Marks | HackerRank

Query the names of students scoring higher than 75 Marks. Sort the output by the LAST three characters of each name.

www.hackerrank.com

Query the Name of any student in STUDENTS who scored higher than 75 Marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID.

SELECT 
    NAME
FROM 
    STUDENTS
WHERE Marks > 75
ORDER BY RIGHT(RTRIM(NAME), 3), ID;

2. Employee Names

https://www.hackerrank.com/challenges/name-of-employees/problem?isFullScreen=true

 

Employee Names | HackerRank

Print employee names.

www.hackerrank.com

Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee table in alphabetical order.

SELECT
    name
FROM 
	Employee
ORDER BY 
	name;

3. Employee Salaries

https://www.hackerrank.com/challenges/salary-of-employees/problem?isFullScreen=true

 

Employee Salaries | HackerRank

Print the names of employees who earn more than $2000 per month and have worked at the company for less than 10 months.

www.hackerrank.com

Write a query that prints a list of employee names (i.e.: the name attribute) for employees in Employee having a salary greater than  $2000per month who have been employees for less than 10 months. Sort your result by ascending employee_id.

SELECT 
    NAME
FROM 
    Employee
WHERE 
    salary > 2000
    AND months < 10
ORDER BY 
    employee_id ASC;

4. Type of Triangle

https://www.hackerrank.com/challenges/what-type-of-triangle/problem?isFullScreen=true

 

Type of Triangle | HackerRank

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

www.hackerrank.com

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  3 sides of equal length.
  • Isosceles: It's a triangle with  2 sides of equal length.
  • Scalene: It's a triangle with  3 sides of differing lengths.
  • Not A Triangle: The given values of A, B, and C don't form a triangle.
SELECT 
    CASE 
        WHEN A + B <= C OR A + C <= B OR B + C <= A 
            THEN 'Not A Triangle'
        WHEN A = B AND B = C
            THEN 'Equilateral'
        WHEN A = B OR B = C OR A = C
            THEN 'Isosceles'
        ELSE 'Scalene'
    END AS triangle_type
FROM TRIANGLES;

POINT!

CASE WHEN이 위에서부터 차례대로 조건을 검사하고 처음 만족하는 조건에서 멈춥니다

그래서 해당 쿼리에서는 하나라도 참이면 나머지 조건이 무시되기 때문에
우선 순위가 중요합니다.

① Not A Triangle(포괄적인 조건) → ② Equilateral(특수한 조건) → ③ Isosceles(그 다음 조건) → ④ Scalene (나머지)

 

5. Revising Aggregations  - The Count Function

https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem?isFullScreen=true

 

Revising Aggregations - The Count Function | HackerRank

Query the number of cities having populations larger than 100000.

www.hackerrank.com

Query a count of the number of cities in CITY having a Population larger than 100,000.

SELECT 
    COUNT(*) AS CITY_COUNT
FROM 
    CITY
WHERE POPULATION > 100000;

6. Revising Aggregations - The Sum Function

https://www.hackerrank.com/challenges/revising-aggregations-sum/problem?isFullScreen=true

 

Revising Aggregations - The Sum Function | HackerRank

Query the total population of all cities for in the District of California.

www.hackerrank.com

SELECT SUM(POPULATION) AS TOTAL_POPULATION
FROM CITY
WHERE DISTRICT = 'California'

7. Revising Aggregations - Averages

https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem?isFullScreen=true

 

Revising Aggregations - Averages | HackerRank

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

www.hackerrank.com

Query the average population of all cities in CITY where District is California.

SELECT AVG(POPULATION) AS AVG_POPULATION
FROM CITY
WHERE DISTRICT = 'California'

 

'코딩 테스트 > 02. SQL' 카테고리의 다른 글

[HackerRank] SQL Basic (easy)(5)  (1) 2025.08.15
[HackerRank] SQL Basic (easy)(4)  (2) 2025.08.14
[HackerRank] SQL Basic (easy)(2)  (8) 2025.08.13
[HackerRank] SQL Basic (easy)(1)  (4) 2025.08.12
[solvesql] Lv2 문제 풀이 및 함수 정리  (8) 2025.08.11
'코딩 테스트/02. SQL' 카테고리의 다른 글
  • [HackerRank] SQL Basic (easy)(5)
  • [HackerRank] SQL Basic (easy)(4)
  • [HackerRank] SQL Basic (easy)(2)
  • [HackerRank] SQL Basic (easy)(1)
Growth DA Log
Growth DA Log
Growth DA Log 님의 블로그 입니다.
  • Growth DA Log
    Growth DA Log님의 블로그
    Growth DA Log
  • 전체
    오늘
    어제
    • 분류 전체보기 (125)
      • TIS_COMPANY (6)
      • 코딩 테스트 (61)
        • 01. Python (3)
        • 02. SQL (58)
      • 데이터 분석 (53)
        • 01. BigQuery (9)
        • 02. GA4 (1)
        • 02-1. GA4를 더 잘 다루기 위한 마케팅 개.. (5)
        • 03. streamlit (5)
        • 04. Git (12)
        • 05. 데이터 엔지니어링 (3)
        • 06. 데이터 모델링 (11)
        • 07. Excel (0)
        • 08. Tableau (4)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    코테
    tableau
    DENSE_RANK
    윈도우함수
    ROW_NUMBER
    코딩테스트
    tableaubootcamp
    rank
    cross_join
    AARRR
    streamlit
    Reset
    쿼리테스트
    revert
    solvesql
    프로그래머스
    git
    이행성
    코드잇스프린트후기
    SQL
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.4
Growth DA Log
[HackerRank] SQL Basic (easy)(3)
상단으로

티스토리툴바