직업별 컬럼을 생성하여 정리하되 doctor, professor, singer, actor순서로 정렬하며
각 컬럼은 alpabet 오름 차순으로 정렬
Data
iSQL> select * from occupations;
NAME OCCUPATION
-----------------------------------------------
Ashley Professor
Samantha Actor
Julia Doctor
Britney Professor
Maria Professor
Meera Professor
Priya Doctor
Priyanka Professor
Jennifer Actor
Ketty Actor
Belvet Professor
Naomi Professor
Jane Singer
Jenny Singer
Kristeen Singer
Christeen Singer
Eve Actor
Aamina Doctor
18 rows selected.
Output
DOCTOR PROFESSOR SINGER ACTOR
---------------------------------------------------------------------------------------------
Aamina Ashley Christeen Eve
Julia Belvet Jane Jennifer
Priya Britney Jenny Ketty
Maria Kristeen Samantha
Meera
Naomi
Priyanka
7 rows selected.
문제 출처: hackerrank
My Answer
select doctor, professor, singer, actor from
(
select rownum rown from (select name as doctor from occupations where occupation = 'Doctor' order by name)
union
select rownum rown from (select name as professor from occupations where occupation = 'Professor' order by name)
union
select rownum rown from (select name as singer from occupations where occupation = 'Singer' order by name)
union
select rownum rown from (select name as actor from occupations where occupation = 'Actor' order by name)
) main,
(select rownum rown, doctor from (select name as doctor from occupations where occupation = 'Doctor' order by name)) a,
(select rownum rown, professor from (select name as professor from occupations where occupation = 'Professor' order by name)) b,
(select rownum rown, singer from (select name as singer from occupations where occupation = 'Singer' order by name)) c,
(select rownum rown, actor from (select name as actor from occupations where occupation = 'Actor' order by name)) d
where main.rown=a.rown(+)
and main.rown=b.rown(+)
and main.rown=c.rown(+)
and main.rown=d.rown(+);
2017년 3월 20일 월요일
피드 구독하기:
댓글 (Atom)
리눅스 문자와숫자 조합의 파일이름 정렬( Sort alphanumeric filenames in Linux )
아래 처럼 문자와 숫자가 섞여 있는 파일에 대해서 정렬이 제대로 되지 않을 때 When sorting is not done properly for files with mixed letters and numbers as shown below [codeh...
-
우선 메뉴에서 Tools아래 Orange Options를 선택 후 Common의 Session에서 Commit automatically after every statement를 체크하면 Autocommit is On으로 변경됨 ...
-
1. 하드웨어 시간 확인 #> hwclock -r 2. 소프트웨어 시간 확인 $, #> date 3. 자동 설정 #> rdate -s time.bora.net 4.수동 설정 #> date -s "201...
-
오라클 설치를 하였으니 테스트용으로 HR 샘플 스키마를 설치한다. oracle@solaris:~$ sqlplus sys as sysdba Connected to: SQL*Plus: Release 18.0.0.0.0 - Producti...
댓글 없음:
댓글 쓰기