IT/코테문제
[Hacker Rank_MySQL]문제 풀이#The PADS
호랑구야
2022. 3. 1. 09:01
SQL > Advanced Select > The PADS
The PADS | HackerRank
Query the name and abbreviated occupation for each person in OCCUPATIONS.
www.hackerrank.com
1. Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S).
2. Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format: There are a total of [occupation_count] [occupation]s.
빨간 글씨는 내가 문제를 풀 때 중요하다고 생각한 부분이다.
두 쿼리를 연달아 작성할 때, 세미콜론으로 앞 쿼리가 끝났다는 것을 표시해야 한다.
이게 없어서 한참 다른 사람들 코드를 찾아봤다.
SELECT CONCAT(NAME,'(', SUBSTR(OCCUPATION, 1, 1), ')')
FROM OCCUPATIONS
ORDER BY NAME ASC;
SELECT CONCAT('There are a total of ', COUNT(OCCUPATION), ' ', LOWER(OCCUPATION), 's.')
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY COUNT(OCCUPATION) ASC, OCCUPATION ASC
반응형