본문 바로가기

Algorithm/MySQL

[해커랭크(HackerRank)] Employee Names (MySQL)

문제

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

Input Format

The Employee table containing employee data for a company is described as follows:

where employee_id is an employee's ID number, name is their name, months is the total number of months they've been working for the company, and salary is their monthly salary.

Sample Input

 

코드

SELECT name
FROM Employee
ORDER BY name

 

풀이

  1. Employee 테이블에서 name 조회
  2. name의 알파벳 순으로 정렬
    ORDER BY 에서 오름차순 정렬은 디폴트 값이기 때문에 컬럼명 뒤에 적지 않아도 됨
    내림차순일 경우 DESC 기재
반응형