Customer Who Visited but Did Not Make Any Transactions
https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/description/
-- 거래없이 방문만 한 사용자 아이디, 방문한 횟수 조회
SELECT
v.customer_id,
count(v.visit_id) count_no_trans
FROM -- 거래내역에서 NULL을 찾아야 하기 때문에 LEFT JOIN으로 모든 값 조회
Visits v LEFT JOIN Transactions t ON t.visit_id = v.visit_id
WHERE t.transaction_id IS NULL
GROUP BY v.customer_id ;
💡 NULL 값을 찾기 위해 LEFT JOIN을 사용해 모든 데이터를 조회
Rising Temperature
https://leetcode.com/problems/rising-temperature/description/
-- 어제보다 온도가 높은 모든 날짜 조회
SELECT
t.id
FROM
weather t
JOIN weather y
ON t.recordDate = DATE_ADD(y.recordDate, INTERVAL 1 DAY)
-- 같은 테이블을 조인하고 한 테이블 날짜 데이터에 하루씩 추가해서 날짜 차이를 줌
WHERE t.temperature > y.temperature ;
💡 뭔가 CROSS JOIN? 도 활용할 수 있을 것 같음
'SQL > 문제' 카테고리의 다른 글
| SQL | Average Selling Price, Percentage of Users Attended a Contest (0) | 2025.01.06 |
|---|---|
| SQL | Students and Examinations, Managers with at Least 5 Direct Reports (1) | 2025.01.06 |
| QCC 1회차 (0) | 2025.01.05 |
| SQL | 상품을 구매한 회원 비율 구하기 (0) | 2025.01.05 |
| SQL | 대여 횟수가 많은 자동차들의 월별 대여 횟수 구하기, 오프라인/온라인 판매 데이터 통합하기, 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기 (1) | 2025.01.05 |