-
[SQL][해커랭크] The PADS / 문자열 출력데이터 분석 공부/SQL 2024. 5. 14. 16:37728x90
https://www.hackerrank.com/challenges/the-pads/problem?isFullScreen=true
The PADS | HackerRank
Query the name and abbreviated occupation for each person in OCCUPATIONS.
www.hackerrank.com
이 문제는 크게 두 쿼리로 나누어서 풀게 되어 있습니다.
쿼리 1 ) 사람이름(직업의 첫글자 따오기)
쿼리 2 ) 직업 별로 몇 명의 사람이 있는지 카운트하여 문장과 함께 출력하기
[ Output ]
Your Output (stdout) Aamina(D) Ashley(P) Belvet(P) Britney(P) Christeen(S) Eve(A) Jane(S) Jennifer(A) Jenny(S) Julia(D) Ketty(A) Kristeen(S) Maria(P) Meera(P) Naomi(P) Priya(D) Priyanka(P) Samantha(A) There are a total of 3 doctors. There are a total of 4 actors. There are a total of 4 singers. There are a total of 7 professors.
[ Query ]
# SELECT CONCAT ('HELLO' , ' ' , 'WORLD') SELECT CONCAT(Name , '(', LEFT(Occupation,1), ')') FROM OCCUPATIONS ORDER BY Name; SELECT CONCAT ('There are a total of ', COUNT(Name), ' ', LOWER(Occupation), 's.') FROM OCCUPATIONS GROUP BY Occupation ORDER BY COUNT(Name), Occupation;
SQL에서 문자열을 출력할 때는 CONCAT 함수를 쓰면 됩니다.
GPT한테 물어봤을 때는 || 기호를 쓰라고 했는데, 이는 MySQL 환경에서는 적용되지 않더라고요.
'데이터 분석 공부 > SQL' 카테고리의 다른 글
[SQL] solvesql 지역별 주문의 특징 / COUNT(DISTINCT CASE WHEN) 절 활용 문제 / 피벗테이블, 집계 (0) 2024.06.13 [SQL][해커랭크] Draw The Triangle 1 / SET @, REPEAT (0) 2024.05.17 [SQL][해커랭크] weather observation station 9, 10 / 정규표현식, 와일드카드 (0) 2024.05.13 mysql start 시 cannot change directory to /nonexistent: No such file or directory 오류 해결 (0) 2024.04.22 DBMS 안에서 데이터베이스 연결하기 (0) 2024.04.17