/*----------------- 3-5 ~ 3-7------------------*/ # left join 강의 시작을 안한 사람 select u.name, count(*) as cnt from users u left join point_users pu on u.user_id = pu.user_id where pu.point_user_id is NULL group by u.name order by count(*) desc # 7월 10일 ~ 7월 19일에 가입한 고객 중, 포인트를 가진 고객의 숫자, 전체 숫자, 비율 select * from point_users select * from users select count(pu.point_user_id) as pnt_user_cnt, count(*) ..
두 테이블의 공통된 필드(key 값)를 기준으로 테이블을 연결해서 한 테이블처럼 보는 것을 의미한다. Join의 종류에는 Left Join, Inner Join이 있다. Left Join은 A 테이블의 왼쪽에 B 테이블을 붙이는 것이다. 이때 해당 데이터의 필드값이 비어있다면 [Null]로 표시되어 출력된다.(A와 B 사이의 크기를 따져야한다.) Inner Join은 두 테이블의 공통된 데이터값만을 출력한다. select * form table을 해보면서 필드값을 확인하고 두 테이블의 공통된 필드값을 찾는다. 이후,(별칭 사용) select * from users u inner join point_users p on u.user_id = p.user_id from --> join --> where -->..
# 별칭 alias 사용해보기 select payment_method, count(*) as cnt from orders o where o.course_title = '앱개발 종합반' group by payment_method # 앱개발 종합반의 결제수단별 주문건수 세어보기 select payment_method, count(*) from orders where course_title = '앱개발 종합반' group by payment_method order by count(*) desc # 구글을 사용하는 성씨별 회원수 세어보기 select name, count(*) from users where email like '%@gmail.com' group by name order by count(*) # ..
# Group by: 동일한 범주의 데이터를 묶어준다. # Order by: 깔끔하게 데이터를 정렬한다. select * from users group by name # 위에서부터 한 번에 쓴다는 생각 말고 위처럼 미리 작성 후 아래와 같이 작성하는 순서로 배우자. select name, count(*) from users group by name # users 테이블 전체 불러오기 select * from users # users 테이블에서 '신'씨를 가진 데이터만 불러와서 개수 살펴보기 select count(*) from users where name like '신**' # group by를 사용해서 '신'씨를 가진 데이터가 몇 개인지 살펴보기 select name, count(*) from use..
# Quiz) # 포인트가 2만 점보다 많은 유저만 뽑아보기! select * from point_users where point >= 20000 # 성이 황씨인 유저만 뽑아보기! select * from users where name = '황**' # 웹개발 종합반이면서 결제수단이 CARD인 주문건만 뽑아보기! select * from orders where course_title = '웹개발 종합반' and payment_method = 'CARD' # 꿀팁) show table로 어떤 테이블이 있는지 살펴보기 # select * from 테이블명 확인하기 # 원하는 정보가 없으면 다른 테이블에도 해보기 # 맞는 테이블을 찾았으면 조건을 걸 필드를 찾기 # select * from 테이블명 where..