문제586. 상호명에 치킨을 포함하고 있는 상호명과 건수를 출력하시오
select 상호명, count(*)
from market
where 상호명 like '%치킨%'
group by 상호명
order by 2 desc;
문제587. 상호명의 끝자리가 점으로 끝나고 상호명에 치킨이 포함된 상호명을 출력하시오(ㄱㄴㄷ순으로)
select 상호명, count(*)
from market
where 상호명 like '%치킨%' and 상호명 like '%점%'
group by 상호명
order by 1 asc;
문제588. 상호명 끝글자가 점으로 끝나는 상호명이 출력될 때 다음과 같이 데이터를 정제하시오.
굽네치킨은천점 > 굽네치킨
select substr(상호명,1,instr(상호명,'킨'))
from market
where 상호명 like '%치킨%' and 상호명 like '%점%'
group by 상호명
order by 1 asc;
문제589. 위의 결과를 다시 출력하는데 case 문을 이용해서 치킨마루, 치킨매니아, 피자나라치킨공주를 정제하시오
select case when 상호명 like '%치킨마루%' then '치킨마루'
when 상호명 like'%치킨매니아%' then '치킨매니아'
when 상호명 like'%피자나라치킨공주%' then '피자나라치킨공주'
else substr(상호명,1,instr(상호명,'킨')) end as 상호
from market
where 상호명 like '%치킨%' and 상호명 like '%점%'
group by 상호명
order by 1 asc;
문제590. 위의 sql을 view로 만들거나 from 절의 서브쿼리로 만들어서 상호를 출력하고 그 옆에 상호별 건수를 출력하는데 상호별 건수가 높은 것부터 출력하시오
select 상호, count(*)
from ( select case when 상호명 like '%치킨마루%' then '치킨마루'
when 상호명 like'%치킨매니아%' then '치킨매니아'
when 상호명 like'%피자나라치킨공주%' then '피자나라치킨공주'
else substr(상호명,1,instr(상호명,'킨')) end as 상호
from market
where 상호명 like '%치킨%' and 상호명 like '%점%'
)
group by 상호
order by 2 desc;
문제591. 매장수 1위인 치킨브랜드를 데이터 분석 홈페이지에서 확인하세요
문제592.
문제593. 아래의 589번 sql과 위의 592번 sql의 결과를 붙여서 출력하시오
select case when 상호명 like '%치킨마루%' then '치킨마루'
when 상호명 like '%치킨매니아%' then '치킨매니아'
when 상호명 like '%피자나라치킨공주%' then '피자나라치킨공주'
else substr(상호명,1,instr(상호명,'킨')) end as 상호명
from market
where 상호명 like '%치킨%' and 상호명 like '%치킨%점%'
union all
select case when 상호명 like '%BBQ치킨%' then 'BBQ치킨'
when 상호명 like '%BHC치킨%' then 'BHC치킨'
else 상호명 end as 상호명
from market
where 상호명 like '%치킨%' and 상호명 not like '%점';
문제594. 위의 sql을 from 절의 서브쿼리로 감싸고 상호명과 상호명별 건수를 출력하시오(건수가 높은 순)
select 상호명, count(*)
from (
select case when 상호명 like '%치킨마루%' then '치킨마루'
when 상호명 like '%치킨매니아%' then '치킨매니아'
when 상호명 like '%피자나라치킨공주%' then '피자나라치킨공주'
else substr(상호명,1,instr(상호명,'킨')) end as 상호명
from market
where 상호명 like '%치킨%' and 상호명 like '%치킨%점%'
union all
select case when 상호명 like '%BBQ치킨%' then 'BBQ치킨'
when 상호명 like '%BHC치킨%' then 'BHC치킨'
else 상호명 end as 상호명
from market
where 상호명 like '%치킨%' and 상호명 not like '%점'
)
group by 상호명
order by 2 desc;
> 데이터 카페에 명철이 코드 참고해서 sql작성할 것
문제595. 올해 2021년 9월 서울시 치킨집 매장수와 2017년 치킨집 매장수를 비교해보시오
create or replace view market2017_view
as
select case when 상호명 like '%60계치킨%' then '60계치킨'
when 상호명 like '%BBQ치킨%' then 'BBQ치킨'
when 상호명 like '%BHC치킨%' then 'BHC치킨'
when 상호명 like '%강호동치킨%' then '강호동치킨'
when 상호명 like '%거성치킨%' then '거성치킨'
when 상호명 like '%경원치킨%' then '경원치킨'
when 상호명 like '%계동치킨%' then '계동치킨'
when 상호명 like '%광화문치킨%' then '광화문치킨'
when 상호명 like '%교촌치킨%' then '교촌치킨'
when 상호명 like '%국대후라이드치킨%' then '국대후라이드치킨'
when 상호명 like '%굽네치킨%' then '굽네치킨'
when 상호명 like '%권석영의미스터짱닭치킨%' then '권석영의미스터짱닭치킨'
when 상호명 like '%그린맘치킨%' then '그린맘치킨'
when 상호명 like '%기발한치킨%' then '기발한치킨'
when 상호명 like '%깐부치킨%' then '깐부치킨'
when 상호명 like '%깜닭이야치킨%' then '깜닭이야치킨'
when 상호명 like '%깻잎두마리치킨%' then '깻잎두마리치킨'
when 상호명 like '%꼬꾸뱅치킨%' then '꼬꾸뱅치킨'
when 상호명 like '%네네치킨%' then '네네치킨'
when 상호명 like '%대니쉬참숯치킨%' then '대니쉬참숯치킨'
when 상호명 like '%더맛존바베큐치킨%' then '더맛존바베큐치킨'
when 상호명 like '%덕앤치킨%' then '덕앤치킨'
when 상호명 like '%도도베르구이치킨%' then '도도베르구이치킨'
when 상호명 like '%돈치킨%' then '돈치킨'
when 상호명 like '%돌돌치킨%' then '돌돌치킨'
when 상호명 like '%동키치킨%' then '동키치킨'
when 상호명 like '%둘둘치킨%' then '둘둘치킨'
when 상호명 like '%디디치킨%' then '디디치킨'
when 상호명 like '%디앤비치킨%' then '디앤비치킨'
when 상호명 like '%또바기치킨%' then '또바기치킨'
when 상호명 like '%라일치킨%' then '라일치킨'
when 상호명 like '%리킨%' then '리킨'
when 상호명 like '%마파치킨%' then '마파치킨'
when 상호명 like '%맛데이치킨%' then '맛데이치킨'
when 상호명 like '%맥시칸치킨%' then '맥시칸치킨'
when 상호명 like '%메이플치킨%' then '메이플치킨'
when 상호명 like '%멕시카나치킨%' then '멕시카나치킨'
when 상호명 like '%멕시칸치킨%' then '멕시칸치킨'
when 상호명 like '%멕켄치킨%' then '멕켄치킨'
when 상호명 like '%못난감자%' then '못난감자앤치킨'
when 상호명 like '%못난감자앤치킨%' then '못난감자앤치킨'
when 상호명 like '%못난감자엔치킨%' then '못난감자엔치킨'
when 상호명 like '%바로화덕치킨%' then '바로화덕치킨'
when 상호명 like '%바른치킨%' then '바른치킨'
when 상호명 like '%박군치킨%' then '박군치킨'
when 상호명 like '%베리웰치킨%' then '베리웰치킨'
when 상호명 like '%보드람치킨%' then '보드람치킨'
when 상호명 like '%본스치킨%' then '본스치킨'
when 상호명 like '%본투비마늘치킨%' then '본투비마늘치킨'
when 상호명 like '%부어치킨%' then '부어치킨'
when 상호명 like '%부촌치킨%' then '부촌치킨'
when 상호명 like '%붐치킨%' then '붐치킨'
when 상호명 like '%브라보치킨%' then '브라보치킨'
when 상호명 like '%브라운치킨%' then '브라운치킨'
when 상호명 like '%비비큐참숯바베큐치킨%' then '비비큐참숯바베큐치킨'
when 상호명 like '%비에이치씨치킨%' then '비에이치씨치킨'
when 상호명 like '%사바사바치킨%' then '사바사바치킨'
when 상호명 like '%산들애치킨%' then '산들애치킨'
when 상호명 like '%삼삼치킨%' then '삼삼치킨'
when 상호명 like '%삼통치킨%' then '삼통치킨'
when 상호명 like '%샤바샤바치킨%' then '샤바샤바치킨'
when 상호명 like '%쇼랜드치킨%' then '쇼랜드치킨'
when 상호명 like '%수준이다른치킨%' then '수준이다른치킨'
when 상호명 like '%순수치킨%' then '순수치킨'
when 상호명 like '%썬더치킨%' then '썬더치킨'
when 상호명 like '%쏘스치킨%' then '쏘스치킨'
when 상호명 like '%아크바치킨%' then '아크바치킨'
when 상호명 like '%에디슨DHA치킨%' then '에디슨DHA치킨'
when 상호명 like '%오꼬꼬치킨%' then '오꼬꼬치킨'
when 상호명 like '%오득항아리치킨%' then '오득항아리치킨'
when 상호명 like '%오부장치킨%' then '오부장치킨'
when 상호명 like '%오븐마루치킨%' then '오븐마루치킨'
when 상호명 like '%오케이치킨%' then '오케이치킨'
when 상호명 like '%윙걸치킨%' then '윙걸치킨'
when 상호명 like '%자담치킨%' then '자담치킨'
when 상호명 like '%잘만든치킨%' then '잘만든치킨'
when 상호명 like '%전국3대치킨%' then '전국3대치킨'
when 상호명 like '%전설의치킨%' then '전설의치킨'
when 상호명 like '%지코바양념치킨%' then '지코바양념치킨'
when 상호명 like '%지코바치킨%' then '지코바치킨'
when 상호명 like '%쭈노치킨%' then '쭈노치킨'
when 상호명 like '%참존숯불바베큐치킨%' then '참존숯불바베큐치킨'
when 상호명 like '%참참치킨%' then '참참치킨'
when 상호명 like '%처갓집양념치킨%' then '처갓집양념치킨'
when 상호명 like '%처갓집치킨%' then '처갓집치킨'
when 상호명 like '%추억의통치킨%' then '추억의통치킨'
when 상호명 like '%충만치킨%' then '충만치킨'
when 상호명 like '%치킨마루%' then '치킨마루'
when 상호명 like '%치킨매니아%' then '치킨매니아'
when 상호명 like '%컬투치킨%' then '컬투치킨'
when 상호명 like '%케이준치킨%' then '케이준치킨'
when 상호명 like '%투마리치킨%' then '투마리치킨'
when 상호명 like '%티바두마리치킨%' then '티바두마리치킨'
when 상호명 like '%파파치킨%' then '파파치킨'
when 상호명 like '%페리카나치킨%' then '페리카나치킨'
when 상호명 like '%피자나라치킨공주%' then '피자나라치킨공주'
when 상호명 like '%하림치킨%' then '하림치킨'
when 상호명 like '%핫썬치킨%' then '핫썬치킨'
when 상호명 like '%호식이두마리치킨%' then '호식이두마리치킨'
when 상호명 like '%호치킨%' then '호치킨'
when 상호명 like '%훌랄라참숯바베큐치킨%' then '훌랄라참숯바베큐치킨'
else 상호명 end as 상호
from market_2017
where 상호명 like '%치킨%'and 시도명 = '서울특별시';
select 상호, count(*)
from market2017_view
group by 상호
order by 2 desc;
문제596. 2017년도에는 존재했던 치킨집매장인데 현재는 폐업한 곳의 총 건수를 출력하시오
select count(*)
from (
select 상가업소번호
from market_2017
where 상호명 like '%치킨%'and 시도명 = '서울특별시'
minus
select 상가업소번호
from market
where 상호명 like '%치킨%');
문제597. 2017년에도 존재했던 치킨집 매장인데 현재에도 존재하는 치킨집 매장은 몇 건인가?
select count(*)
from (
select 상가업소번호
from market_2017
where 상호명 like '%치킨%'and 시도명 = '서울특별시'
intersect
select 상가업소번호
from market
where 상호명 like '%치킨%');
문제598. 2017년도에는 존재했던 치킨집 매장인데 현재에는 없는 상호명과 행정동명을 출력하시오
select *
from (
select 행정동명, count(행정동명), rank() over (order by count(행정동명) desc) as 순위
from market_2017
where 상가업소번호 in ( select 상가업소번호
from market_2017
where 상호명 like '%치킨%' and 시도명 = '서울특별시'
minus
select 상가업소번호
from market
where 상호명 like '%치킨%' )
group by 행정동명 )
where 순위 = 1;
반응형
'Study > class note' 카테고리의 다른 글
sql중급 / with절(subauery factoring) (0) | 2021.12.01 |
---|---|
sql중급 / with절 (0) | 2021.11.30 |
sql중급 / primary key, unique, not null, check, foreign key (0) | 2021.11.29 |
sql중급/ flachback version query, transaction query (0) | 2021.11.29 |
sql 중급 / flashback query,table, drop (0) | 2021.11.26 |