일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- array.slice()
- array.push()
- Developer_JoyKim
- 프로그래머스
- 개발자_조이킴
- 블록체인
- Programmers
- 코딩테스트
- Hackerrank
- 코딩공부
- Where
- Algorithms
- 자바스크립트
- 역행자
- join
- 알고리즘
- array
- 최강의 인생
- node.js
- 정규표현식
- JavaScript
- select
- 개발자의 책장
- 배열
- 재귀함수
- 코플릿
- SQL
- for문
- 코드스테이츠
- MySQL
- Today
- Total
CodingSpace
[HackerRank/SQL] Advanced Select - The PADS 본문
Problem. Advanced Select - The PADS
Link.
The PADS | HackerRank
Query the name and abbreviated occupation for each person in OCCUPATIONS.
www.hackerrank.com
Description.
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:
- There are a total of [occupation_count] [occupation]s.
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.
다음 두 결과 set를 반환하는 SQL문을 작성하시오.
Key Point.
CONCAT, 여러 문자열 혹은 컬럼 값을 합쳐서 반환하는 함수
- ex) CONCAT('Hi', ' ', 'I am', ' ', 'Joy') → ('Hi I am Joy)
SUBSTRING, 문자열을 추출하는 함수
- SUBSTRING(원본 분자열, 시작 위치 값, 가져올 문자열의 길이 값)
- ex) SUBSTRING('Doctor', 1, 1) → 'D'
LOWER, 소문자 변경 함수
- LOWER(문자열)
- ex) LOWER('AbcD') → 'abcd'
UPPER, 소문자 변경 함수
- UPPER(문자열)
- ex) UPPER('abCd') → 'ABCD'
My Answer.
SELECT CONCAT(NAME, '(', Substring(OCCUPATION, 1, 1), ')') as Name
FROM OCCUPATIONS
ORDER BY NAME;
SELECT CONCAT('There are a total of', ' ', COUNT(OCCUPATION), ' ', LOWER(OCCUPATION),'s.') as TOTAL
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY TOTAL;
References.
CONCAT: https://extbrain.tistory.com/52
[MySQL] 여러 문자열를 하나의 문자열로 합치기 (CONCAT 함수)
▶MySQL 여러 문자열를 하나의 문자열로 합치기 (CONCAT 함수) ▶설명 간혹 여러 문자열 혹은 컬럼 값을 합쳐서 가져와야 하는 경우가 있습니다. 이 때 사용하는 함수가 CONCAT 함수입니다. CONCAT 함수
extbrain.tistory.com
'HackerRank > SQL' 카테고리의 다른 글
[HackerRank/SQL] Basic Join - Average Population of Each Continent (0) | 2022.06.08 |
---|---|
[HackerRank/SQL] Basic Join - Population Census (0) | 2022.05.26 |
[HackerRank/SQL] Advanced Select - Type of Triangle (0) | 2022.05.12 |
[HackerRank/SQL] Basic Select - Employee Names (0) | 2022.05.07 |
[HackerRank/SQL] Basic Select - Higher Than 75 Marks (feat. RIGHT) (0) | 2022.05.06 |