Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์‹ํ’ˆ๋ถ„๋ฅ˜๋ณ„ ๊ฐ€์žฅ ๋น„์‹ผ ์‹ํ’ˆ์˜ ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ(2์ฐจ ํ’€์ด)

์ธ” 2023. 1. 13. 06:25

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์€ Growth/Practice ๊ฒŒ์‹œ๊ธ€ (https://sy038680.tistory.com/242๋ฌธ์ œ์— ๋Œ€ํ•œ 2์ฐจ ํ’€์ด์ž…๋‹ˆ๋‹ค.

 


๊ธฐ์กด ํ’€์ด์—์„œ๋Š” WHERE์ ˆ์— ์„œ๋ธŒ์ฟผ๋ฆฌ๋กœ ์กฐ์ธํ•ด์„œ ๊ฐ€๊ฒฉ ์ตœ๋Œ€๊ฐ’์„ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„๋กœ ์ถ”์ถœํ•ด์„œ

๋ฉ”์ธ ์ฟผ๋ฆฌ ์กฐ๊ฑด์—์„œ ๋ฌธ์ œ์—์„œ ์š”๊ตฌํ•˜๋Š” ์นดํ…Œ๊ณ ๋ฆฌ๋งŒ ์ถ”์ถœํ•ด์„œ ์ถœ๋ ฅ.

์ƒˆ๋กœ ํ’€๋ฉด์„œ๋Š” WHERE์ ˆ์— () IN ์œผ๋กœ ํ‘ผ ๋‹ค๋ฅธ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฐ๋‚˜์„œ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์ตœ๋Œ€๊ฐ€๊ฒฉ์„

์ด ๋ฌธ๋ฒ•์œผ๋กœ ์ถœ๋ ฅํ•˜๋ฉด์„œ AND๋กœ ์กฐ๊ฑด ์ถ”๊ฐ€ํ•ด์„œ ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ๋ฏธ๋ฆฌ ๊ฑธ๋Ÿฌ์ค˜๋ณด์•˜๋‹ค.

SELECT CATEGORY, PRICE AS MAX_PRICE, PRODUCT_NAME
 FROM FOOD_PRODUCT
 WHERE (CATEGORY, PRICE) IN (SELECT CATEGORY, MAX(PRICE)
                             FROM FOOD_PRODUCT
                             WHERE CATEGORY IN ('๊ณผ์ž','๊ตญ','๊น€์น˜','์‹์šฉ์œ ')
                             GROUP BY 1)
 ORDER BY 2 DESC