예제126. 우리나라 남자들이 가장 많이 걸리는 암은 무엇인가?(2018년과 2021년 데이터 비교)
문제634. 2018년도에 남자들이 가장 많이 걸리는 암과 환자수와 순위를 출력하시오
select distinct 암종, 환자수, 순위
from (
select 암종, 환자수, dense_rank() over (order by 환자수 desc nulls last) as 순위
from cancer
where 성별 = '남자' and 암종 <> '모든암')
order by 순위 asc;
문제635. 2018년도에 여자들이 가장 많이 걸리는 암과 환자수와 순위를 출력하시오.
select distinct 암종, 환자수, 순위
from (
select 암종, 환자수, dense_rank() over (order by 환자수 desc nulls last) as 순위
from cancer
where 성별 = '여자' and 암종 <> '모든암')
where 순위 = 1;
문제636. 1999년도~ 2018년도까지의 전체 데이터를 가지고 남자와 여자가 가장 많이 걸리는 암과 환자수와 순위를 각각 출력하시오
select 암종, cnt, rank() over (order by cnt desc nulls last) 순위
from (
select 암종, sum(발생자수) cnt
from cancer_total
where 성 = '남자' and 암종 != '모든암'
group by 암종
);
select 암종, cnt, rank() over (order by cnt desc nulls last) 순위
from (
select 암종, sum(발생자수) cnt
from cancer_total
where 성 = '여자' and 암종 != '모든암'
group by 암종
);
문제637. 1999년도에 비해서 2018년도에 순위가 상승한 암종은 무엇이고 순위가 하락한 암종은 무엇인가요?
select 암종, 발생자수, rank() over (order by 발생자수 desc nulls last) 순위
from cancer_total
where 성 = '남자' and 암종 != '모든암' and 발생연도 = 1999;
select 암종, 발생자수, rank() over (order by 발생자수 desc nulls last) 순위
from cancer_total
where 성 = '남자' and 암종 != '모든암' and 발생연도 = 2018;
select 암종, 발생자수, rank() over (order by 발생자수 desc nulls last) 순위
from cancer_total
where 성 = '여자' and 암종 != '모든암' and 발생연도 = 1999;
select 암종, 발생자수, rank() over (order by 발생자수 desc nulls last) 순위
from cancer_total
where 성 = '여자' and 암종 != '모든암' and 발생연도 = 2018;
예제127. 스티븐 잡스 연설문에서 가장 많이 나오는 단어는 무엇인가?
select word, count(*)
from ( select rtrim(trim('"' from regexp_substr(lower(speech_text),'[^ ]+',1,n)),'.,;:!?') as word
from speech, ( select level as n
from dual
connect by level <= 100) )
where word is not null
group by word
order by 2 desc;
예제128. 스티브 잡스 연설문에는 긍정단어가 많은지 부정단어가 많이 나올까
-- 긍정단어 : 87건
select count(*)
from stev_text s
where exists ( select 'X'
from positive p
where p.p_text = s.word );
-- 부정단어 : 55건
select count(*)
from stev_text s
where exists ( select 'X'
from negative p
where p.n_text = s.word );
문제638. 월간 구독료를 받는 썸트랜드처럼 긍정, 부정 감정분석을 해보는데 스티브잡스 연설문에 많이 나오는 긍정 단어와 그 건수와 순위를 출력하시오 (speech, positive 테이블 이용)
select word, count(*) cnt, rank() over (order by count(*) desc)
from stev_text s
where exists ( select 'X'
from positive p
where p.p_text = s.word )
group by word;
예제129. 절도가 가장 많이 발생하는 요일은 언제인가?
select 요일, rank() over (order by 건수 desc) 순위
from (
select *
from crime_day
unpivot (건수 for 요일 in (일, 월, 화, 수, 목, 금, 토 ))
where 범죄분류 = '절도' );
문제639. 도로교통법(사고후미조치)가 가장 많이 발생하는 요일은 언제인가요?
select 요일, rank() over (order by 건수 desc) 순위
from (
select *
from crime_day
unpivot (건수 for 요일 in (일, 월, 화, 수, 목, 금, 토 ))
where 범죄분류 = '도로교통법(사고후미조치)' );
예제130. 우리나라에서 대학 등록금이 가장 비싼 학교는?
select *
from ( select 대학명, 평균등록금, rank() over (order by 평균등록금 desc) 순위
from univ )
where 순위 between 1 and 10;
문제640. (SQL 마지막 문제) 자기 자신이 다녔던 학교의 평균 등록금이 전국에서 몇위의 순위인지 확인하시오.
select *
from ( select 대학명, 평균등록금, rank() over (order by 평균등록금 desc) 순위
from univ )
where 대학명 = '단국대학교';
'Study > class note' 카테고리의 다른 글
sql / TCL (0) | 2021.12.06 |
---|---|
sql / DCL (0) | 2021.12.06 |
문제8. SQL / 마름모 출력하기 (0) | 2021.12.03 |
sql / 알고리즘문제2 (0) | 2021.12.02 |
sql / 알고리즘 문제 (0) | 2021.12.01 |