[LeetCode] 1581. Customer Who Visited but Did Not Make Any Transactions

Chobby·2025년 9월 23일
1

LeetCode

목록 보기
552/582

😎풀이

  1. VisitsTransactions LEFT JOIN
  2. 방문하지 않은 고객은 검색 조건에서 제외
  3. customer_id를 기준으로 그룹화
  4. 미거래 방문 수에 따라 오름차 순 정렬렬
SELECT 
    v.customer_id,
    COUNT(*) AS count_no_trans
FROM
    Visits AS v
LEFT JOIN
    Transactions AS t
ON
    v.visit_id = t.visit_id
WHERE
    t.visit_id IS NULL
GROUP BY
    v.customer_id
ORDER BY
    count_no_trans;
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글