- 이름과 직업의 첫 글자를 합쳐서 출력 ex) name : ace occupaion : Doctor -> ace(D)
- 각 직업의 수를 출력 -> There are a total of [직업 카운트] [직업]s.
select concat(name,'(',left(occupation,1),')')
from OCCUPATIONS
order by name, substr(occupation,1,1);
1. concat, left를 사용해서 각 직업의 첫 글자를 따와서 이름에 뒤에 합쳐준다.
2. 문제에서 제시되는 정렬 조건에 맞춰서 정렬
select concat("There are a total of ",count(occupation),' ',lower(occupation),'s.')
from occupations
group by occupation
order by count(occupation), occupation;
3.There are a total of 직업 카운트 직업s. 를 출력하기 위해 앞에 문자열을 넣어주고 각 직업을 그룹화해서 카운트해준다.
그리고 직업명을 소문자로 출력해야 하므로 lower로 감싸주고 concat으로 합쳐주면 된다.
select concat(name,'(',left(occupation,1),')')
from OCCUPATIONS
order by name, substr(occupation,1,1);
select concat("There are a total of ",count(occupation),' ',lower(occupation),'s.')
from occupations
group by occupation
order by count(occupation), occupation;
'코드카타' 카테고리의 다른 글
[해커랭크] Binary Tree Nodes (0) | 2024.01.26 |
---|---|
[해커랭크] Placements (1) | 2024.01.24 |
[hackerrank] The Report (1) | 2024.01.23 |
[leetcode] 1934. Confirmation Rate (0) | 2024.01.22 |
[SQL]프로그래머스 Lv.4 그룹별 조건에 맞는 식당 목록 출력하기 (1) | 2023.12.27 |