문제 출저
문제 풀이
거래 없이 방문한 사용자의 아이디와 방문 횟수를 구해야 합니다.
Transactions 테이블에 방문 아이디를 가져옵니다. Visits 테이블에서 가져온 아이디에 일치하는게 없으면 거래 없이 방문한 것 입니다. whrere에 not in 을 사용합니다. customer_id 별로 횟수를 구해야 하므로 group by를 사용합니다.
SQL
# 거래 없이 방문한 사용자의 아이디와 방문 횟수를 구해야 한다.
select
customer_id,
count(*) as count_no_trans
from
Visits as v
where
visit_id not in (select distinct visit_id from Transactions)
group by
customer_id
/*
select customer_id,count(customer_id) as count_no_trans
from visits
left join transactions
on visits.visit_id=transactions.visit_id
where transactions.visit_id is null
group by customer_id
*/