[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋Œ€์—ฌ ํšŸ์ˆ˜๊ฐ€ ๋งŽ์€ ์ž๋™์ฐจ๋“ค์˜ ์›”๋ณ„ ๋Œ€์—ฌ ํšŸ์ˆ˜ ๊ตฌํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ๋Œ€์—ฌ ํšŸ์ˆ˜๊ฐ€ ๋งŽ์€ ์ž๋™์ฐจ๋“ค์˜ ์›”๋ณ„ ๋Œ€์—ฌ ํšŸ์ˆ˜ ๊ตฌํ•˜๊ธฐํ’€์ดSELECT TO_NUMBER(TO_CHAR(START_DATE, 'MM')) MONTH, CAR_ID, COUNT(*) RECORDSFROM CAR_RENTAL_COMPANY_RENTAL_HISTORYWHERE CAR_ID IN ( SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE TO_CHAR(START_DATE, 'YYYYMM') >= '202208' AND TO_CHAR(START_DATE, 'YYYYMM') = 5 ) AND TO_CHAR(START_DATE, 'YYYYMM') >= '202208' AND TO_CHAR(START_DATE, 'YYYYMM') ..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ž…์–‘ ์‹œ๊ฐ ๊ตฌํ•˜๊ธฐ(2) | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์ž…์–‘ ์‹œ๊ฐ ๊ตฌํ•˜๊ธฐ(2)ํ’€์ดSELECT A.HOUR, COUNT(B.DATETIME) COUNTFROM (SELECT LEVEL - 1 AS HOUR FROM DUAL CONNECT BY LEVEL COUNT(*)์„ ํ•˜๋ฉด ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์–ด๋„ 1๋กœ ์ถœ๋ ฅํ•˜๊ธฐ ๋•Œ๋ฌธ์—, COUNT(B.DATETIME)์œผ๋กœ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.0๋ถ€ํ„ฐ 23์„ ๊ฐ€์ง„ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ ์œ„ํ•ด CONNECT BY(๊ณ„์ธต์  ์ฟผ๋ฆฌ)๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.์ฐธ๊ณ ์˜ค๋ผํด ์ˆœ๋ฒˆ ์ฑ„๋ฒˆ CONNECT BY LEVEL ํ™œ์šฉํ•˜๊ธฐ[Oracle] ์˜ค๋ผํด CONNECT BY ์‚ฌ์šฉ๋ฒ• (๊ณ„์ธตํ˜• ์ฟผ๋ฆฌ)
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋…„, ์›”, ์„ฑ๋ณ„ ๋ณ„ ์ƒํ’ˆ ๊ตฌ๋งค ํšŒ์› ์ˆ˜ ๊ตฌํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์‹ํ’ˆ๋ถ„๋ฅ˜๋ณ„ ๊ฐ€์žฅ ๋น„์‹ผ ์‹ํ’ˆ์˜ ์ •๋ณด ์กฐํšŒํ•˜๊ธฐํ’€์ดSELECT TO_CHAR(B.SALES_DATE, 'YYYY') YEAR, TO_NUMBER(TO_CHAR(B.SALES_DATE, 'MM')) MONTH, GENDER, COUNT(DISTINCT A.USER_ID) USERSFROM USER_INFO A JOIN ONLINE_SALE B ON A.USER_ID = B.USER_IDWHERE GENDER IS NOT NULLGROUP BY TO_CHAR(B.SALES_DATE, 'YYYY'), TO_NUMBER(TO_CHAR(B.SALES_DATE, 'MM')), GENDERORDER BY 1, 2, 3;1์ž๋ฆฌ ์ˆซ์ž์˜ ๋‹ฌ์˜ ๊ฒฝ์šฐ ์•ž์˜ 0์„ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด, TO_NUMBER๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.์ค‘๋ณต๋˜๋Š” ์œ ์ €๊ฐ€..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์‹ํ’ˆ๋ถ„๋ฅ˜๋ณ„ ๊ฐ€์žฅ ๋น„์‹ผ ์‹ํ’ˆ์˜ ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์‹ํ’ˆ๋ถ„๋ฅ˜๋ณ„ ๊ฐ€์žฅ ๋น„์‹ผ ์‹ํ’ˆ์˜ ์ •๋ณด ์กฐํšŒํ•˜๊ธฐํ’€์ดSELECT CATEGORY, PRICE MAX_PRICE, PRODUCT_NAMEFROM FOOD_PRODUCTWHERE (CATEGORY, PRICE) IN ( SELECT CATEGORY, MAX(PRICE) FROM FOOD_PRODUCT WHERE CATEGORY IN ('๊ณผ์ž', '๊ตญ', '๊น€์น˜', '์‹์šฉ์œ ') GROUP BY CATEGORY)ORDER BY MAX_PRICE DESC;์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ณดํ˜ธ์†Œ์—์„œ ์ค‘์„ฑํ™”ํ•œ ๋™๋ฌผ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ๋ณดํ˜ธ์†Œ์—์„œ ์ค‘์„ฑํ™”ํ•œ ๋™๋ฌผํ’€์ดSELECT AI.ANIMAL_ID, AI.ANIMAL_TYPE, AI.NAMEFROM ANIMAL_INS AI JOIN ANIMAL_OUTS AOON AI.ANIMAL_ID = AO.ANIMAL_IDWHERE (AI.SEX_UPON_INTAKE LIKE 'Intact%') AND (AO.SEX_UPON_OUTCOME LIKE 'Spayed%' OR AO.SEX_UPON_OUTCOME LIKE 'Neutered%')ORDER BY 1;WHERE ์กฐ๊ฑด์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค.WHERE AI.SEX_UPON_INTAKE LIKE 'Intact%' AND AO.SEX_UPON_OUTCOME NOT LIKE 'Intact%'
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜คํ”„๋ผ์ธ/์˜จ๋ผ์ธ ํŒ๋งค ๋ฐ์ดํ„ฐ ํ†ตํ•ฉํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์˜คํ”„๋ผ์ธ/์˜จ๋ผ์ธ ํŒ๋งค ๋ฐ์ดํ„ฐ ํ†ตํ•ฉํ•˜๊ธฐํ’€์ดSELECT TO_CHAR(SALES_DATE, 'YYYY-MM-DD') SALES_DATE, PRODUCT_ID, USER_ID, SALES_AMOUNTFROM ( SELECT SALES_DATE, PRODUCT_ID, USER_ID, SALES_AMOUNT FROM ONLINE_SALE UNION SELECT SALES_DATE, PRODUCT_ID, NULL, SALES_AMOUNT FROM OFFLINE_SALE)WHERE TO_CHAR(SALES_DATE, 'YYYY-MM-DD') LIKE '2022-03%'ORDER BY 1, 2, 3;UNION์„ ์‚ฌ์šฉํ•˜์—ฌ ํ’€์ดํ–ˆ์Šต๋‹ˆ๋‹ค.UNION์€ ์ค‘๋ณต๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ , UNION ALL..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์„œ์šธ์— ์œ„์น˜ํ•œ ์‹๋‹น ๋ชฉ๋ก ์ถœ๋ ฅํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์ž๋™์ฐจ ๋Œ€์—ฌ ๊ธฐ๋ก ๋ณ„ ๋Œ€์—ฌ ๊ธˆ์•ก ๊ตฌํ•˜๊ธฐํ’€์ดSELECT A.REST_ID, A.REST_NAME, A.FOOD_TYPE, A.FAVORITES, A.ADDRESS, B.REVIEW_SCOREFROM REST_INFO A JOIN (SELECT REST_ID, ROUND(AVG(REVIEW_SCORE), 2) REVIEW_SCORE FROM REST_REVIEW GROUP BY REST_ID) BON A.REST_ID = B.REST_IDWHERE A.ADDRESS LIKE '์„œ์šธ%'ORDER BY REVIEW_SCORE DESC, FAVORITES DESC;REST_ID์™€ ๋ฆฌ๋ทฐ์ ์ˆ˜ ํ‰๊ท  ๋‘ ๊ฐœ์˜ ์ปฌ๋Ÿผ์„ ๊ฐ–๋Š” ์ธ๋ผ์ธ ๋ทฐ๋ฅผ ๋งŒ๋“ค์–ด ์กฐ์ธํ•˜์—ฌ ํ’€์ดํ•˜์˜€์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv0] ์ˆจ์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๋ง์…ˆ (2) | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/Programmers Lv0
๋ฌธ์ œ์ˆจ์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๋ง์…ˆ (2)ํ’€์ดclass Solution { public int solution(String my_string) { int answer = 0; String[] strArr = my_string.replaceAll("[a-zA-Z]", " ").split(" "); for(String str : strArr) { if(!str.equals("")) answer += Integer.parseInt(str); } return answer; }}๋ชจ๋“  ์•ŒํŒŒ๋ฒณ์„ ์ œ๊ฑฐํ•ด์•ผํ•˜๋Š”๋ฐ replaceAll("[a-zA-Z]", " ")๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ์•ŒํŒŒ๋ฒณ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ฆ๊ฒจ์ฐพ๊ธฐ๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ์‹๋‹น ์ •๋ณด ์ถœ๋ ฅํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์ฆ๊ฒจ์ฐพ๊ธฐ๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ์‹๋‹น ์ •๋ณด ์ถœ๋ ฅํ•˜๊ธฐํ’€์ดSELECT FOOD_TYPE, REST_ID, REST_NAME, FAVORITESFROM REST_INFOWHERE (FOOD_TYPE, FAVORITES) IN ( SELECT FOOD_TYPE, MAX(FAVORITES) FROM REST_INFO GROUP BY FOOD_TYPE)ORDER BY FOOD_TYPE DESC;GROUP BY๋ฅผ ์ด์šฉํ•ด์„œ ์Œ์‹๋ณ„ ์ตœ๋Œ€ ์ฆ๊ฒจ์ฐพ๊ธฐ ์ˆ˜๋ฅผ ๋ฝ‘์€ ์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ ํ’€์ดํ•ฉ๋‹ˆ๋‹ค.