Tags
- outer join
- DB
- migrations
- regexp
- Django
- 통계학
- update
- N:1
- count
- M:N
- Vue
- SQL
- 쟝고
- ORM
- 큐
- distinct
- 이진트리
- stack
- 완전검색
- 뷰
- 트리
- Tree
- 그리디
- 백트래킹
- delete
- Queue
- create
- Article & User
- 스택
- drf
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Notice
Recent Posts
Link
데이터 분석 기술 블로그
서브쿼리 기초 3 * 본문
문제 3: 특정 날짜 이후의 거래 내역
데이터셋 1: transactions
transaction_id | customer_id | date | amount |
1 | 101 | 2023-01-01 | 200 |
2 | 102 | 2023-03-15 | 500 |
3 | 103 | 2023-02-10 | 300 |
4 | 101 | 2023-04-20 | 400 |
5 | 102 | 2023-05-25 | 600 |
데이터셋 2: customers
customer_id | name |
101 | Alice |
102 | Bob |
103 | Charlie |
문제
'Alice' 고객이 거래한 가장 최근 날짜 이후에 거래한 모든 고객의 이름과 거래 내역을 출력하세요.
CREATE TABLE transactions (
transaction_id INT PRIMARY KEY,
customer_id INT,
date DATE,
amount INT
);
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name VARCHAR(50)
);
INSERT INTO transactions (transaction_id, customer_id, date, amount) VALUES
(1, 101, '2023-01-01', 200),
(2, 102, '2023-03-15', 500),
(3, 103, '2023-02-10', 300),
(4, 101, '2023-04-20', 400),
(5, 102, '2023-05-25', 600);
INSERT INTO customers (customer_id, name) VALUES
(101, 'Alice'),
(102, 'Bob'),
(103, 'Charlie');
SELECT c.name, t.date, t.amount
FROM transactions t
JOIN customers c ON t.customer_id = c.customer_id
WHERE t.date > (
SELECT MAX(t2.date)
FROM transactions t2
JOIN customers c2 ON t2.customer_id = c2.customer_id
WHERE c2.name = 'Alice'
);
'SQL > 문제풀이' 카테고리의 다른 글
Game Play Analysis IV _ Medium. LeetCode * (0) | 2025.01.02 |
---|---|
Monthly Transactions I _ Medium. LeetCode * (0) | 2025.01.01 |
서브쿼리 기초 2 (0) | 2024.12.26 |
서브쿼리 기초 1 (0) | 2024.12.25 |
Fix Names in a Table _ Easy. LeetCode * (0) | 2024.11.01 |