Customer Who Visited but Did Not Make Any Transactions

수이·2025년 4월 16일

🟢 코드카타 / SQL

목록 보기
84/88
post-thumbnail

Write a solution to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.
Return the result table sorted in any order.
문제링크

조건정리

  1. visit은 있으나 transaction에는 없는 고객 횟수
  2. customer_id, count_no_trans 출력

풀이

  1. visits가 더 큰 테이블이니까 left join으로 묶음
  2. transaction_id 가 null인 것 찾고 count로 세기
  3. customer_id별로 그룹화해주면 끝
SELECT v.customer_id, count(1) AS count_no_trans
FROM visits v 
LEFT JOIN transactions t ON v.visit_id = t.visit_id
WHERE t.transaction_id IS NULL
GROUP BY v.customer_id

0개의 댓글