반응형
https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/description/
join을 사용해본 문제였습니다.
📕 풀이방법
📔 풀이과정
visit_id로 visits와 transactions table을 join한 후 customer_id로 goup by햐 transaction_id가 null인 column의 visit_id를 count해 준 후 customer_id와 함께 select합니다.
📕 Code
📔 ANSI SQL
select v.customer_id, count(v.visit_id) 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
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'SQL' 카테고리의 다른 글
(SQL) - LeetCode (easy) 1656. Design an Ordered Stream (0) | 2024.05.27 |
---|---|
(SQL) - LeetCode (easy) 1587. Bank Account Summary II (0) | 2024.05.02 |
(SQL) - LeetCode (easy) 1407. Top Travellers (0) | 2024.03.12 |
(SQL) - LeetCode (easy) 1378. Replace Employee ID With The Unique Identifier (0) | 2024.02.26 |
(Tibero 7) - varray 찍먹하기 (0) | 2024.02.05 |