๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Coding Test/SQL

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์šฐ์œ ์™€ ์š”๊ฑฐํŠธ๊ฐ€ ๋‹ด๊ธด ์žฅ๋ฐ”๊ตฌ๋‹ˆ/MySQL - Lv.4

by The Future Engineer, Lucy 2024. 9. 29.
728x90
๋ฐ˜์‘ํ˜•

โ“๋ฌธ์ œ

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

๐Ÿ“Œ์œ ํ˜•

 SELECT, GROUP BY

โœ๐Ÿปํ’€์ด

์šฐ์œ ๋ฅผ ๊ตฌ๋งคํ•œ CART_ID๋“ค ์ค‘์— CART_ID๊ฐ€ ํ•ด๋‹นํ•˜๊ณ  ์š”๊ฑฐํŠธ๋„ ๊ตฌ๋งคํ•œ CART_ID๋งŒ ์ถœ๋ ฅ.

๐Ÿ’ป์ฝ”๋“œ

SELECT CART_ID
FROM CART_PRODUCTS
WHERE CART_ID IN (SELECT CART_ID
                  FROM CART_PRODUCTS
                  WHERE NAME = 'Milk')
    AND NAME = 'Yogurt'
GROUP BY CART_ID
728x90
๋ฐ˜์‘ํ˜•