우유와 요거트가 담긴 장바구니
https://school.programmers.co.kr/learn/courses/30/lessons/62284
- 문제 풀이
1
2
3
4
5
6
7
8
9
SELECT CART_ID
FROM (
SELECT DISTINCT(CART_ID), NAME, PRICE
FROM CART_PRODUCTS
WHERE NAME IN ('Milk', 'Yogurt')
)
GROUP BY CART_ID
HAVING COUNT(*) >= 2
ORDER BY CART_ID;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SELECT C.CART_ID
FROM CART_PRODUCTS C
, (
SELECT CART_ID, COUNT(*) AS COUNT
FROM CART_PRODUCTS
WHERE NAME LIKE 'Yog%'
GROUP BY CART_ID
HAVING COUNT(*) = 1
) YO
, (
SELECT CART_ID, COUNT(*) AS COUNT
FROM CART_PRODUCTS
WHERE NAME LIKE 'Mil%'
GROUP BY CART_ID
HAVING COUNT(*) = 1
) MK
WHERE C.CART_ID = YO.CART_ID
AND C.CART_ID = MK.CART_ID
GROUP BY C.CART_ID
ORDER BY C.CART_ID
- 실행 결과
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.