일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- airflow.cfg
- PostgreSQL
- matplotlib
- 그로스해킹
- 결측값
- SQL
- join
- GROUPBY
- hackerrank
- 프로그래머스
- Limit
- Oracle
- 데이터분석
- 전처리
- SQLite
- MySQL
- pandas
- 머신러닝
- 파이썬
- Round
- not in
- solvesql
- 다중 JOIN
- seaborn
- airflow 설치
- 데이터리안 웨비나
- having
- 데이터시각화
- TRUNCATE
- SUM
Archives
- Today
- Total
Milky's note
[HackerRank](M) The PADS 본문
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.
[답]
-mysql
select concat(name,'(',left(occupation,1),')') from OCCUPATIONS
order by name;
select concat('There are a total of ',count(occupation),' ',lower(occupation),'s.')
from OCCUPATIONS
group by occupation
order by count(occupation), occupation;
쿼리 하나로 조회하는 조건은 아니다.
먼저 이름과 직업을 조회하기 위해 concat을 사용해서 출력해주었다.
다음으론 직업의 수를 조회하기 위해 count을 사용했고, concat을 이용해서 문장에 출력해주었다.
출력 예시가 직업이 소문자로 되어있어서 lower를 해주었고,
정렬 순서가 직업의 갯수와 알파벳 순이어서 다음과 같이 정렬을 해주었다.
'SQL > SQL 코딩 테스트-HackerRank' 카테고리의 다른 글
[HackerRank](E) Revising Aggregations - The Count Function (0) | 2022.03.25 |
---|---|
[HackerRank](M) Binary Tree Nodes (0) | 2022.03.18 |
[HackerRank](E) Type of Triangle (0) | 2022.03.18 |
[HackerRank](E) Employee Salaries (0) | 2022.03.18 |
[HackerRank](E) Employee Names (0) | 2022.03.18 |
Comments