두 테이블간 교집합인 필드를 기준으로 하나의 테이블처럼 보이게 만들어줌
select * from point_users
inner join users on point_users.user_id = users.user_id
: point_users 테이블의 user_id 필드와
users 테이블의 user_id를 교집합으로 하나의 테이블처럼 보이게 함.
테이블1
의 필드1
과 테이블2
의 필드1
를 join 할 때↓↓↓테이블1-필드1
에는 존재하지만 테이블2-필드1
에는 값이 존재하지 않을 때 Null값으로 표기count
는 Null 값을 세지 않음.where '필드이름' is Null
- Null의 'N'은 대문자로 표기!!where '필드이름' is not Null
테이블1-필드1
와 테이블2-필드1
모두에 존재하는 값만 나타냄.두가지 조건의 결과를 이어 하나의 결과값으로 이어서 보기
(
select '7월' as month, c.title, c2.week, count(*) as cnt from checkins c2
inner join courses c on c2.course_id = c.course_id
inner join orders o on o.user_id = c2.user_id
where o.created_at < '2020-08-01'
group by c2.course_id, c2.week
order by c2.course_id, c2.week
)
union all
(
select '8월' as month, c.title, c2.week, count(*) as cnt from checkins c2
inner join courses c on c2.course_id = c.course_id
inner join orders o on o.user_id = c2.user_id
where o.created_at > '2020-08-01'
group by c2.course_id, c2.week
order by c2.course_id, c2.week
)
갑자기 직장인이 되버린 나는... 마지막날에 몰아치고 있다..... 그래도 SQL은 쉬워서 금방끝낼 수 있겠다. 웹코딩이 문제다ㅎㅎㅎ