SQL 기초 3일차

전윤환·2022년 3월 8일
0

SQL왕초보

목록 보기
3/6

학습일자: 2022/03/09
재수강일: 2022/04/02
삼수강일: 2022/04/29
강의: 엑셀보다 쉬운 SQL
진도: 2-6 ~ 2-7

앱개발 듣다가 SQL 들으니까 너무 재밌음 ㅠㅠ
신나게 문제 풀어보자~

=====================

앱개발 종합반의 결제수단별 주문건수 세어보기

select course_title, payment_method, count(*) from orders
where course_title = '앱개발 종합반'
group by payment_method 

Gmail 을 사용하는 성씨별 회원수 세어보기

select name, count(*) from users
where email like '%gmail.com'
group by name
order by count(*) desc

course_id별 '오늘의 다짐'에 달린 평균 like 개수 구해보기

select course_id, round(avg(likes), 1) from checkins
group by course_id

아 재밌다~~~ 달다 달아 ㅋㅋㅋㅋ

=====================

별칭 기능 : Alias

select * from orders o
where o.course_title = '앱개발 종합반'

orders 테이블을 o라고 부르겠다.
o라고 이름붙인 orders 테이블의 course_title이 앱개발 종합반인 자료를 출력해라.

=====================

별칭 두번째 : as

select payment_method, count(*) as cnt from orders o
where o.course_title = '앱개발 종합반'
group by payment_method 

스크린샷에서 cnt라고 보이는 곳은 원래 count(*)라고 보여야 하는데, as cnt를 붙였더니 cnt라고 컬럼명이 지정된다.

=====================

2주차 마지막 퀴즈

네이버 이메일을 사용하여 앱개발 종합반을 신청한 주문의 결제수단별 주문건수 세어보기

select course_title as 수강코스, payment_method as 결제수단, count(*) as 주문건수 from orders
where email like '%naver.com'
and course_title = '앱개발 종합반'
group by payment_method 

profile
코딩 연습장. 발전하고 싶습니다. 모든 방향에서의 비판 부탁드립니다.

0개의 댓글