Banner

My Tech Blog (์ฟผ๋ฆฌ)

๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…โŒ ์‹คํŒจํ•œ ์‹œ๋„์ด๋ฆ„์˜ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ณ„ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ถ€๋ถ„์ด  ๋ฌธ์ œ์˜ ํ•ต์‹ฌ 1์ฐจ ์‹œ๋„ ์‹คํŒจWHERE ์ ˆ์—์„œ `LOWER(NAME)` ํ•ด ์ฃผ์—ˆ์œผ๋‚˜ ํ‹€๋ฆผ์ฟผ๋ฆฌ๋Š” ๋Œ์•„๊ฐ€๊ณ  ๊ฒฐ๊ณผ๋Š” ๋‚˜์˜ค์ง€๋งŒ ๊ฒฐ๊ตญ WHERE์ ˆ์—์„œ LOWER()๊ณผ LIKE๋ฅผ ํ•จ๊ป˜ ์“ด ๊ฒƒ์€ ๋ถˆํ•„์š”ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. MySQL์—์„œ LIKE ์—ฐ์‚ฐ์ž๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ณ„ํ•˜์ง€ ์•Š๋Š”๋‹ค. SELECT ANIMAL_ID, NAMEFROM ANIMAL_INSWHERE LOWER(ANIMAL_TYPE) = 'dog' AND LOWER(NAME) LIKE '%el%'ORDER BY NAME DESC; 2์ฐจ ์‹œ๋„ ์‹คํŒจ์ด๋ฒˆ์—๋Š” ORDER BY์ ˆ์— LOWER() ํ•จ์ˆ˜๋ฅผ ์จ์„œ ์ •๋ ฌํ–ˆ๋”๋‹ˆ ํ‹€๋ ธ๋‹ค๊ณ  ํ•จ.WHERE ์ ˆ์ด๋ž‘ ์ •๋ ฌ์ด๋ž‘ ๋ณ„๊ฐœ๋‹ˆ๊นŒ ์ •๋ ฌ์—๋Š” LOW..
๐Ÿ“‘ 1. ํŠน์ • ์˜ต์…˜์ด ํฌํ•จ๋œ ์ž๋™์ฐจ ๋ฆฌ์ŠคํŠธ ๊ตฌํ•˜๊ธฐ ๋ฌธ์ œCAR_RENTAL_COMPANY_CAR ํ…Œ์ด๋ธ”์—์„œ '๋„ค๋น„๊ฒŒ์ด์…˜' ์˜ต์…˜์ด ํฌํ•จ๋œ ์ž๋™์ฐจ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ๊ฒฐ๊ณผ๋Š” ์ž๋™์ฐจ ID๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”. โญ ์ •๋‹ต์ฝ”๋“œSELECT * FROM CAR_RENTAL_COMPANY_CARWHERE OPTIONS LIKE '%๋„ค๋น„๊ฒŒ์ด์…˜%'ORDER BY CAR_ID DESC;๐Ÿ“‘ 2. ์ž๋™์ฐจ ๋Œ€์—ฌ ๊ธฐ๋ก์—์„œ ์žฅ๊ธฐ/๋‹จ๊ธฐ ๋Œ€์—ฌ ๊ตฌ๋ถ„ํ•˜๊ธฐ ๐Ÿ“Œ ํ‹€๋ฆฐ์ฝ”๋“œSELECT HISTORY_ID, CAR_ID, DATE_FORMAT(START_DATE, '%Y-%m-%d'), DATE_FORMAT(END_DATE, '%Y-%m-%d'), CASE WHEN DATEDIFF(END_DATE..
1. ๊ฒŒ์‹œ๊ธ€  ์ˆ˜์ •ํ•˜๋Š” update ๋ฉ”์„œ๋“œ ๋งŒ๋“ค๊ธฐBbsDAO ํด๋ž˜์Šค ํ•˜๋‹จ์— ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€public int update(int bbsID, String bbsTitle, String bbsContent) { String SQL = "UPDATE BBS SET bbsTitle = ?, bbsContent = ? WHERE bbsID = ?"; PreparedStatement psmt = null; try { psmt = conn.prepareStatement(SQL); psmt.setString(1, bbsTitle); psmt.setString(2, bbsContent); psmt.setInt(3, bbsID); return p..
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…๐Ÿ’ก 2. ์ ‘๊ทผ๋ฐฉ์‹FILE_PATH ์ถœ๋ ฅ ์˜ˆ์‹œ๋ฅผ ๋ณด๊ณ  '/home/grep/src/' + F.BOARD_ID + '/' + F.FILE_ID + F.FILE_NAME + F.FILE_EXT์ด๋ ‡๊ฒŒ ๋ฌธ์ž์—ด์ด ๊ฒฐํ•ฉ๋œ ๊ตฌ์กฐ๋ผ๋Š” ๊ฑธ ์•Œ ์ˆ˜ ์žˆ์—ˆ๋‹ค. CONCAT์œผ๋กœ ํ•ด๋‹น ๋ฌธ์ž์—ด์„ ๋ชจ๋‘ ๊ฒฐํ•ฉ ํ•ด ์ค€๋‹ค. ์ฒ˜์Œ์—๋Š” ํ—ท๊ฐˆ๋ ค์„œ + ์—ฐ์‚ฐ์ž๋กœ ํ–ˆ๋Š”๋ฐ ,๋กœ ๊ฒฐํ•ฉ์„ ํ•ด ์ค˜์•ผ ํ•œ๋‹ค.  ๋‘ ํ…Œ์ด๋ธ” ์กฐ์ธํ•  ๋•Œ๋Š” BOARD_ID ์ปฌ๋Ÿผ์„ ๊ธฐ์ค€์œผ๋กœ ์กฐ์ธ ํ•ด ์ค€๋‹ค. WHERE ์ ˆ์—์„œ ์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ์“ด๋‹ค. ๋จผ์ € USED_GOODS_BOARD๋ฅผ ์กฐํšŒ์ˆ˜ ์ปฌ๋Ÿผ(VIEW) ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ํ•ด ์ฃผ๊ณ  ๊ทธ ์ค‘ ๊ฐ€์žฅ ๋†’์€ ๊ฒƒ๋งŒ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋‹ˆ๊นŒ LIMIT1 ์„ ๊ฑธ์–ด์ค€๋‹ค.  ๋งˆ์ง€๋ง‰์œผ๋กœ FILE_ID๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•˜๋ฉด ๋~! ์‰ฝ๋‹คโญ 3. ์ •๋‹ต์ฝ”๋“œ..
1. ๋ฌธ์ œ์„ค๋ช… 2. ์ ‘๊ทผ๋ฐฉ์‹ ๋จผ์ € FISH_INFO ํ…Œ์ด๋ธ”์ด๋ž‘ FISH_NAME_INFO ํ…Œ์ด๋ธ”์„ FISH_TYPE ์ปฌ๋Ÿผ์œผ๋กœ ์กฐ์ธ ํ•ด ์ค€๋‹ค. ๊ทธ๋ฆฌ๊ณ  FISH_NAME์œผ๋กœ GROUP BY ํ•ด ์ฃผ๊ณ , LENGTH์˜ MAX ๊ฐ’์„ ๊ตฌํ•ด์ฃผ๋ฉด ๋œ๋‹ค๊ณ  ์ƒ๊ฐ ํ–ˆ๋‹ค. ๐Ÿ™…๐Ÿป‍โ™€๏ธ์ฒซ๋ฒˆ์งธ ์‹œ๋„(์‹คํŒจ) ์ผ๋‹จ ์ด๊ฒŒ ๋‚ด๊ฐ€ ์ฒ˜์Œ์— ์ƒ๊ฐํ–ˆ๋˜ ์ฟผ๋ฆฌ์ด๋‹ค. ๋ฐ”๋กœ ๊ตฌ๋ฌธ ์˜ค๋ฅ˜๊ฐ€ ๋–ด๋‹ค. GROUP BY์ ˆ์— ์ง‘๊ณ„๋˜์ง€ ์•Š์€ ์ปฌ๋Ÿผ A.ID๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜๋Š” ์˜ค๋ฅ˜ ๋ฉ”์„ธ์ง€๊ฐ€ ๋–ด๋‹ค. ํ˜„์žฌ GROUP BY ์ ˆ์— B.FISH_NAME๋งŒ ์žˆ๊ณ , A.ID๋Š” GROUP BY์— ํฌํ•จ๋˜์ง€ ์•Š์•„์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค. ORDER BY์— A.ID๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, ๊ทธ ์—ด์ด GROUP BY ์ ˆ์— ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด ๊ฒฐ๊ณผ๊ฐ€ ์˜ˆ๊ธฐ์น˜ ์•Š๊ฒŒ ๋‚˜ํƒ€๋‚  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ GROUP..
1. ๋ฌธ์ œ์„ค๋ช… 2. ์ ‘๊ทผ๋ฐฉ์‹ & ์ •๋‹ต์ฝ”๋“œSELF JOIN์œผ๋กœ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ๋™์ผํ•œ ํ…Œ์ด๋ธ” ๋‚ด์—์„œ ์กฐ์ธํ•ด์„œ ํ’€์–ด์ฃผ์ž.ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”์— ALIAS๋ฅผ ์ค˜์„œ ๋งˆ์น˜ ๋‘ ๊ฐœ์˜ ํ…Œ์ด๋ธ”์ด ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋‘ ๋ฒˆ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด๋‹ค.  ๋‚ด๊ฐ€ ์•Œ๊ณ  ์žˆ๋Š” ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ SELF JOIN ์˜ˆ์‹œ๋Š” ์ง์›๋ณ„ ๋งค๋‹ˆ์ €๋ฅผ ๋‚˜ํƒ€๋‚ธ 1๊ฐœ์˜ ํ…Œ์ด๋ธ”์„ ์ž๊ธฐ์ž์‹ ๊ณผ ์กฐ์ธํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋˜ ๊ณ„์ธต์ฟผ๋ฆฌ์—์„œ๋„ SELF JOIN์ด ๋งŽ์ด ์“ฐ์ธ๋‹ค. ์ด ๋ฌธ์ œ์—์„œ๋„ ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”์— ๋ถ€๋ชจ์˜ ์•„์ด๋””์™€ ์ž์‹์˜ ์•„์ด๋””, ๊ฐœ์ฒด์˜ ํ˜•์งˆ(GENOTYPE)์ด ๋ชจ๋‘ ๋“ค์–ด ์žˆ๋‹ค. ๋ถ€๋ชจ์˜ ํ…Œ์ด๋ธ”์€ P๋กœ, ์ž์‹์˜ ํ…Œ์ด๋ธ”์€ ๊ทธ๋ƒฅ A๋ผ๊ณ  ๋ณ„์นญ์„ ์ค€ ๋’ค ์ž์‹ํ…Œ์ด๋ธ”์˜ PARENT_ID์ปฌ๋Ÿผ์„ ๋ถ€๋ชจ ํ…Œ์ด๋ธ”์˜ ID ๊ฐ’์œผ๋กœ ์กฐ์ธ ํ•œ๋‹ค. ๊ทธ ํ›„ WHERE ์ ˆ์— `A.GENOTYPE & P.GENOTYPE ..
๐Ÿ“‘ ๋ชจ๋“  ๋ ˆ์ฝ”๋“œ ์กฐํšŒํ•˜๊ธฐ10์ดˆ์ปท ๋ฌธ์ œSELECT *FROM ANIMAL_INSORDER BY ANIMAL_ID; ๐Ÿฆ ์กฐ๊ฑด์— ๋งž๋Š” ํšŒ์›์ˆ˜ ๊ตฌํ•˜๊ธฐSELECT COUNT(*)FROM USER_INFOWHERE YEAR(JOINED) = '2021' AND AGE BETWEEN 20 AND 29;๐Ÿ’ป Python ๊ฐœ๋ฐœ์ž ์ฐพ๊ธฐ ๋ณดํ†ต ์Œฉ์ดˆ๋ณด๋“ค์ด ํ‘ธ๋Š” ๋ฐฉ๋ฒ•SELECT ID, EMAIL, FIRST_NAME, LAST_NAMEFROM DEVELOPER_INFOSWHERE SKILL_1 = 'Python' OR SKILL_2 = 'Python' OR SKILL_3 = 'Python'ORDER BY ID; ํ•œ ๋ฒˆ ์ƒ๊ฐ ํ•ด ๋ณด๊ณ  ํ’€๋ฉด ์ด๋ ‡๊ฒŒ ใ…Žใ…Žใ…ŽSELECT ID, EMAIL, FIRST_NAME, L..
๐Ÿ“š์กฐ๊ฑด์— ๋งž๋Š” ๋„์„œ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅํ•˜๊ธฐ ์•„๋ž˜๋Š” ์ •๋‹ต์ฒ˜๋ฆฌ ๋˜๋Š” ๋ชจ๋‘ ๋™์ผํ•œ ์ฝ”๋“œ์ด๋‹ค BETWEEN ์—ฐ์‚ฐ์ž๋กœ ํ’€๊ธฐSELECT BOOK_ID, DATE_FORMAT(PUBLISHED_DATE, '%Y-%m-%d') AS PUBLISHED_DATEFROM BOOKWHERE PUBLISHED_DATE BETWEEN '20210101' AND '20211231' AND CATEGORY LIKE '์ธ๋ฌธ'ORDER BY PUBLISHED_DATE; โญโญโญYEAR() ํ•จ์ˆ˜๋กœ ํ’€๊ธฐ (์ œ์ผ ๊ฐ„๋‹จํ•œ ์ฝ”๋“œ)SELECT BOOK_ID, DATE_FORMAT(PUBLISHED_DATE, '%Y-%m-%d') AS PUBLISHED_DATEFROM BOOKWHERE YEAR(PUBLISHED_DATE) = 2021 ..
์ธ์ ˆ๋ฏธ์˜€๋˜๊ฒƒ
'์ฟผ๋ฆฌ' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก
์ƒ๋‹จ์œผ๋กœ