728x90
반응형
https://www.hackerrank.com/challenges/the-pads/problem?isFullScreen=true
문제
Generate the following two result sets:
- 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).
- Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:
where [occupation_count] is the number of occurrences of an occupation in OCCUPATIONS and [occupation] is the lowercase occupation name. If more than one Occupation has the same [occupation_count], they should be ordered alphabetically.
There are a total of [occupation_count] [occupation]s.
Note: There will be at least two entries in the table for each type of occupation.
Input Format
The OCCUPATIONS table is described as follows:
Occupation will only contain one of the following values: Doctor, Professor, Singer or Actor.
Code
SELECT CONCAT(NAME, '(', LEFT(OCCUPATION, 1), ')')
FROM OCCUPATIONS
ORDER BY NAME, LEFT(OCCUPATION, 1);
SELECT CONCAT('There are a total of ', COUNT(*), ' ', LOWER(OCCUPATION), 's.')
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY COUNT(*), OCCUPATION;
728x90
반응형
'SQL > MySQL' 카테고리의 다른 글
[MySQL/HackerRank] Revising Aggregations - The Sum Function (0) | 2023.08.21 |
---|---|
[MySQL/HackerRank] Revising Aggregations - The Count Function (0) | 2023.08.21 |
[MySQL/HackerRank] Type of Triangle (0) | 2023.08.18 |
[MySQL/HackerRank] Employee Salaries (0) | 2023.08.18 |
[MySQL/HackerRank] Employee Names (0) | 2023.08.18 |