[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜คํ”„๋ผ์ธ/์˜จ๋ผ์ธ ํŒ๋งค ๋ฐ์ดํ„ฐ ํ†ตํ•ฉํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ 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์™€ ๋ฆฌ๋ทฐ์ ์ˆ˜ ํ‰๊ท  ๋‘ ๊ฐœ์˜ ์ปฌ๋Ÿผ์„ ๊ฐ–๋Š” ์ธ๋ผ์ธ ๋ทฐ๋ฅผ ๋งŒ๋“ค์–ด ์กฐ์ธํ•˜์—ฌ ํ’€์ดํ•˜์˜€์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ฆ๊ฒจ์ฐพ๊ธฐ๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ์‹๋‹น ์ •๋ณด ์ถœ๋ ฅํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ 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๋ฅผ ์ด์šฉํ•ด์„œ ์Œ์‹๋ณ„ ์ตœ๋Œ€ ์ฆ๊ฒจ์ฐพ๊ธฐ ์ˆ˜๋ฅผ ๋ฝ‘์€ ์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ ํ’€์ดํ•ฉ๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ฃผ๋ฌธ๋Ÿ‰์ด ๋งŽ์€ ์•„์ด์Šคํฌ๋ฆผ๋“ค ์กฐํšŒํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์ฃผ๋ฌธ๋Ÿ‰์ด ๋งŽ์€ ์•„์ด์Šคํฌ๋ฆผ๋“ค ์กฐํšŒํ•˜๊ธฐํ’€์ดSELECT FLAVORFROM ( SELECT FLAVOR, SUM(TOTAL_ORDER) SUM FROM ( SELECT * FROM FIRST_HALF UNION ALL SELECT * FROM JULY ) GROUP BY FLAVOR ORDER BY SUM DESC) WHERE ROWNUM ์ƒ๋ฐ˜๊ธฐ์™€ 7์›”์— ๊ฐ€์žฅ ๋งŽ์ด ํŒ”๋ฆฐ FLAVOR๋ฅผ ์ˆœ์„œ๋Œ€๋กœ 3๊ฐœ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ์ƒ๋ฐ˜๊ธฐ ํŒ๋งค์ •๋ณด์™€ 7์›” ํŒ๋งค์ •๋ณด ์ค‘ ๊ฒน์น˜๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์—, UNION ALL์„ ์‚ฌ์šฉํ•ด์„œ ํ’€์ดํ–ˆ์Šต๋‹ˆ๋‹ค. *์ฐธ๊ณ  : UNION์€ ์ค‘๋ณต๋œ row๋ฅผ ์ œ์™ธํ•˜๊ณ (DISTINCT), UNION ALL์€ ์ค‘๋ณต๋œ row๋„ ..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ทจ์†Œ๋˜์ง€ ์•Š์€ ์ง„๋ฃŒ ์˜ˆ์•ฝ ์กฐํšŒํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์ทจ์†Œ๋˜์ง€ ์•Š์€ ์ง„๋ฃŒ ์˜ˆ์•ฝ ์กฐํšŒํ•˜๊ธฐํ’€์ดSELECT A.APNT_NO, P.PT_NAME, P.PT_NO, A.MCDP_CD, D.DR_NAME, A.APNT_YMDFROM APPOINTMENT A JOIN PATIENT P ON A.PT_NO = P.PT_NO JOIN DOCTOR D ON A.MCDP_CD = D.MCDP_CD AND A.MDDR_ID = D.DR_IDWHERE TO_CHAR(A.APNT_YMD, 'YYYYMMDD') = '20220413' AND A.MCDP_CD = 'CS' AND A.APNT_CNCL_YN = 'N'ORDER BY A.APNT_YMD;
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ž๋™์ฐจ ๋Œ€์—ฌ ๊ธฐ๋ก ๋ณ„ ๋Œ€์—ฌ ๊ธˆ์•ก ๊ตฌํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์ž๋™์ฐจ ๋Œ€์—ฌ ๊ธฐ๋ก ๋ณ„ ๋Œ€์—ฌ ๊ธˆ์•ก ๊ตฌํ•˜๊ธฐํ’€์ดSELECT AA.HISTORY_ID, (AA.RENT_DATE * AA.DAILY_FEE) * (100 - NVL(DISCOUNT_RATE, 0)) / 100 FEEFROM (SELECT HISTORY_ID, H.END_DATE - H.START_DATE + 1 RENT_DATE, CASE WHEN H.END_DATE - H.START_DATE + 1 >= 90 THEN '90์ผ ์ด์ƒ' WHEN H.END_DATE - H.START_DATE + 1 >= 30 THEN '30์ผ ์ด์ƒ' WHEN H.END_DATE - H.START_DATE + 1 >= ..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์กฐ๊ฑด์— ๋งž๋Š” ์‚ฌ์šฉ์ž ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
[level 3] ์กฐ๊ฑด์— ๋งž๋Š” ์‚ฌ์šฉ์ž ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ - 164670๋ฌธ์ œ ๋งํฌ์„ฑ๋Šฅ ์š”์•ฝ๋ฉ”๋ชจ๋ฆฌ: 0.0 MB, ์‹œ๊ฐ„: 0.00 ms๊ตฌ๋ถ„์ฝ”๋”ฉํ…Œ์ŠคํŠธโ€…์—ฐ์Šต > String๏ผŒโ€…Dateํ’€์ดSELECT USER_ID, NICKNAME, CITY || ' ' || STREET_ADDRESS1 || ' ' || STREET_ADDRESS2 ์ „์ฒด์ฃผ์†Œ, SUBSTR(TLNO, 1, 3) || '-' || SUBSTR(TLNO, 4, 4) || '-' || SUBSTR(TLNO, 8, 4) ์ „ํ™”๋ฒˆํ˜ธFROM USED_GOODS_USERWHERE USER_ID IN ( SELECT WRITER_ID FROM USED_GOODS_BOARD GROUP BY WRITER_ID HAVING COUNT..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜ค๋žœ ๊ธฐ๊ฐ„ ๋ณดํ˜ธํ•œ ๋™๋ฌผ(2) | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
๋ฌธ์ œ์˜ค๋žœ ๊ธฐ๊ฐ„ ๋ณดํ˜ธํ•œ ๋™๋ฌผ(2)ํ’€์ดSELECT *FROM ( SELECT I.ANIMAL_ID, I.NAME FROM ANIMAL_INS I JOIN ANIMAL_OUTS O ON I.ANIMAL_ID = O.ANIMAL_ID ORDER BY O.DATETIME - I.DATETIME DESC)WHERE ROWNUM DATETIME์„ ๋นผ์„œ ์ •๋ ฌ์„ ํ•  ์ƒ๊ฐ์„ ์ฒ˜์Œ์— ํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์กฐํšŒ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ์ค‘๊ณ ๊ฑฐ๋ž˜ ๊ฒŒ์‹œํŒ์˜ ์ฒจ๋ถ€ํŒŒ์ผ ์กฐํšŒํ•˜๊ธฐ | ์˜ค๋ผํด
ยท
๐Ÿ“ Coding Test/SQL
[level 3] ์กฐํšŒ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ๋งŽ์€ ์ค‘๊ณ ๊ฑฐ๋ž˜ ๊ฒŒ์‹œํŒ์˜ ์ฒจ๋ถ€ํŒŒ์ผ ์กฐํšŒํ•˜๊ธฐ - 164671๋ฌธ์ œ ๋งํฌ์„ฑ๋Šฅ ์š”์•ฝ๋ฉ”๋ชจ๋ฆฌ: 0.0 MB, ์‹œ๊ฐ„: 0.00 ms๊ตฌ๋ถ„์ฝ”๋”ฉํ…Œ์ŠคํŠธโ€…์—ฐ์Šต > String๏ผŒโ€…Date์ •๋‹ตSELECT '/home/grep/src/' || B.BOARD_ID || '/' || B.FILE_ID || B.FILE_NAME || B.FILE_EXT FILE_PATHFROM USED_GOODS_BOARD A JOINUSED_GOODS_FILE BON A.BOARD_ID = B.BOARD_IDWHERE VIEWS = ( SELECT MAX(VIEWS) FROM USED_GOODS_BOARD)ORDER BY FILE_ID DESC;์ฐธ๊ณ ์ค‘์ฒฉ ์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์ฐธ๊ณ  : ์„œ๋ธŒ์ฟผ..