코딩 테스트 연습/[프로그래머스][리트코드] MySQL

1581. Customer Who Visited but Did Not Make Any Transactions

duswjd_data 2025. 8. 19. 09:28

문제

https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/description/


문제 설명

  • 쇼핑몰에 방문한 고객들 중 아무 거래도 하지 않고 방문만 한 경우를 찾아, 각 고객이 그런 방문을 몇 번 했는지 구하기
  • 단, 한 번도 거래 없이 방문하지 않은 고객은 제외

정답 코드

SELECT v.customer_id, 
       COUNT(*) 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