๐Ÿ’ซ ๋ฌธ์ œ



ย 

๐Ÿ’ซ CODE

SELECT a.REST_ID, a.REST_NAME, a.FOOD_TYPE, a.FAVORITES, a.ADDRESS, ROUND(AVG(b.REVIEW_SCORE), 2) AS SCORE
FROM REST_INFO a
JOIN REST_REVIEW b ON a.REST_ID = b.REST_ID
WHERE a.ADDRESS LIKE '์„œ์šธ%'
GROUP BY a.REST_ID, a.REST_NAME, a.FOOD_TYPE, a.FAVORITES, a.ADDRESS
ORDER BY SCORE DESC, a.FAVORITES DESC;
SELECT a.REST_ID, a.REST_NAME, a.FOOD_TYPE, a.FAVORITES, a.ADDRESS, ROUND(b.SCORE, 2) AS SCORE
FROM REST_INFO a
JOIN (
    SELECT REST_ID, AVG(REVIEW_SCORE) AS SCORE 
    FROM REST_REVIEW 
    GROUP BY REST_ID) 
    b ON a.REST_ID = b.REST_ID
WHERE ADDRESS LIKE '์„œ์šธ%'
GROUP BY a.REST_ID, a.REST_NAME, a.FOOD_TYPE, a.FAVORITES, a.ADDRESS
ORDER BY SCORE DESC, FAVORITES DESC;

ย 

๐Ÿ’ซ ํ’€์ด ์กฐ๊ฑด

1. ์„œ์šธ์— ์œ„์น˜ํ•œ ์‹๋‹น๋“ค
2. ์‹๋‹น ID(REST_ID), ์‹๋‹น ์ด๋ฆ„(REST_NAME), ์Œ์‹ ์ข…๋ฅ˜(FOOD_TYPE), ์ฆ๊ฒจ์ฐพ๊ธฐ์ˆ˜(FAVORITES), ์ฃผ์†Œ(ADDRESS), ๋ฆฌ๋ทฐ ํ‰๊ท  ์ ์ˆ˜ ์กฐํšŒ
3. ๋ฆฌ๋ทฐ ํ‰๊ท ์ ์ˆ˜๋Š” ์†Œ์ˆ˜์  ์„ธ ๋ฒˆ์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผ
4. ํ‰๊ท ์ ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
5. ํ‰๊ท ์ ์ˆ˜๊ฐ€ ๊ฐ™๋‹ค๋ฉด ์ฆ๊ฒจ์ฐพ๊ธฐ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ

ย 

๐Ÿ’ซ ํ’€์ด

1. SELECT a.REST_ID, a.REST_NAME, a.FOOD_TYPE, a.FAVORITES, a.ADDRESS, ROUND(AVG(b.REVIEW_SCORE), 2) AS SCORE
  • ์‹๋‹น ID(REST_ID), ์‹๋‹น ์ด๋ฆ„(REST_NAME), ์Œ์‹ ์ข…๋ฅ˜(FOOD_TYPE), ์ฆ๊ฒจ์ฐพ๊ธฐ์ˆ˜(FAVORITES), ์ฃผ์†Œ(ADDRESS), ๋ฆฌ๋ทฐ ํ‰๊ท  ์ ์ˆ˜ ์กฐํšŒ
  • ROUND(์ปฌ๋Ÿผ, ์ˆซ์ž)๋ฅผ ์ด์šฉํ•˜์—ฌ ์†Œ์ˆ˜์  ์„ธ ๋ฒˆ์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผ
  • AVG() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ํ‰๊ท  ์ ์ˆ˜ ๊ณ„์‚ฐ
2. JOIN REST_REVIEW b ON a.REST_ID = b.REST_ID
  • JOIN์„ ์ด์šฉํ•˜์—ฌ REST_REVIEW ํ…Œ์ด๋ธ” ์กฐ์ธ
  • ๊ณตํ†ต ์ปฌ๋Ÿผ ์ง€์ •
3. WHERE a.ADDRESS LIKE '์„œ์šธ%'
  • LIKE๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ์šธ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ฃผ์†Œ ์ฐพ๊ธฐ
  • ์—ฌ๊ธฐ์„œ ๊ณ„์† ํ‹€๋ ธ๋Š”๋ฐ ๋ฌธ์ œ์˜ ์ฃผ์†Œ๊ฐ€ ์„œ์šธํŠน๋ณ„์‹œ๋„ ์žˆ๊ณ  ์„œ์šธ์‹œ๋„ ์žˆ์–ด์„œ ์„œ์šธ๋กœ ํ•ด์•ผ ์ •๋‹ต ์ฒ˜๋ฆฌ !
4. GROUP BY a.REST_ID, a.REST_NAME, a.FOOD_TYPE, a.FAVORITES, a.ADDRESS
  • GROUP BY๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ทธ๋ฃน ์ง€์ •
5. ORDER BY SCORE DESC, a.FAVORITES DESC
  • ํ‰๊ท ์ ์ˆ˜(SCORE)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ, ํ‰๊ท ์ ์ˆ˜๊ฐ€ ๊ฐ™๋‹ค๋ฉด ์ฆ๊ฒจ์ฐพ๊ธฐ์ˆ˜(FAVORITES)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ

By Dozzing

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค