SQL - CASE WHEN
ยท
DB/SQL
CASE WHEN THEN END ์˜ˆ์ œ https://programmers.co.kr/learn/courses/30/lessons/59409 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ค‘์„ฑํ™” ์—ฌ๋ถ€ ํŒŒ์•…ํ•˜๊ธฐ ANIMAL_INS ํ…Œ์ด๋ธ”์€ ๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. ANIMAL_INS ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ, ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE๋Š” ๊ฐ๊ฐ ๋™๋ฌผ์˜ ์•„์ด๋”” programmers.co.kr SELECT ANIMAL_ID, NAME, CASE WHEN SEX_UPON_INTAKE LIKE 'Neutered%' OR SEX_UPON_INTAKE LIKE 'Spayed%' THEN 'O' ELSE 'X..
SQL - ์—ฐ์‚ฐ์ž IN
ยท
DB/SQL
ํŠน์ • ์นผ๋Ÿผ์˜ ๊ฐ’์ด ์ฃผ์–ด์ง„ ๊ฐ’ ์ง‘ํ•ฉ์— ์†ํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒ€์‚ฌ ์˜ˆ์ œ https://programmers.co.kr/learn/courses/30/lessons/59046 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฃจ์‹œ์™€ ์—˜๋ผ ์ฐพ๊ธฐ ANIMAL_INS ํ…Œ์ด๋ธ”์€ ๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. ANIMAL_INS ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ, ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE๋Š” ๊ฐ๊ฐ ๋™๋ฌผ์˜ ์•„์ด๋”” programmers.co.kr SELECT ANIMAL_ID, NAME, SEX_UPON_INTAKE FROM ANIMAL_INS WHERE NAME IN ('Lucy', 'Ella', 'Pickle', 'Rogan', ..
SQL - JOIN
ยท
DB/SQL
JOIN์˜ ์ข…๋ฅ˜ Cartesian Product(๊ณฑ์ง‘ํ•ฉ) : ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋ฐฉ๋ฒ•์œผ๋กœ ๊ฒฐํ•ฉํ•จ. Equi-join : ๊ฐ ํ…Œ์ด๋ธ”์—์„œ ํ•˜๋‚˜์”ฉ ์นผ๋Ÿผ์„ ์„ ํƒํ•˜์—ฌ ๊ทธ ๊ฐ’๋“ค์ด ๊ฐ™์€ ํ–‰๋“ค๋งŒ ์„œ๋กœ ์—ฐ๊ฒฐ์‹œํ‚ด. Non-Equi-join : ๋™๋“ฑ ๋น„๊ต ์™ธ์˜ ๋‹ค๋ฅธ ์—ฐ์‚ฐ์ž ์‚ฌ์šฉ. Self-join : ์ž๊ธฐ ์ž์‹ ๊ณผ ์กฐ์ธ ์ˆ˜ํ–‰. Outer Join : ์กฐ์ธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ์•Š๋Š” ํ–‰๋“ค๋„ ๊ฒฐ๊ณผ์— ํฌํ•จ์‹œํ‚ด. - left, right ์˜ˆ์ œ Outer Join https://programmers.co.kr/learn/courses/30/lessons/59042 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์—†์–ด์ง„ ๊ธฐ๋ก ์ฐพ๊ธฐ ANIMAL_INS ํ…Œ์ด๋ธ”์€ ๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. ANIMAL_INS ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ, ANIMAL_..
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค SQL - ์ƒ์œ„ n๊ฐœ ๋ ˆ์ฝ”๋“œ
ยท
DB/SQL
https://programmers.co.kr/learn/courses/30/lessons/59405 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ƒ์œ„ n๊ฐœ ๋ ˆ์ฝ”๋“œ ANIMAL_INS ํ…Œ์ด๋ธ”์€ ๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. ANIMAL_INS ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ, ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE๋Š” ๊ฐ๊ฐ ๋™๋ฌผ์˜ ์•„์ด๋”” programmers.co.kr Oracle์—์„œ ์ƒ์œ„ n๊ฐœ ๋ ˆ์ฝ”๋“œ๋งŒ ๊ฐ€์ ธ์˜ค๋Š” ์ฟผ๋ฆฌ๊ฐ€ ์ƒ๊ฐ์ด ๋‚˜์งˆ ์•Š์•˜๋‹ค. FROM ์—์„œ ์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ์จ์•ผ ํ–ˆ์—ˆ๋„ค.. Oracle์ด ์ต์ˆ™ํ•˜๊ธด ํ•œ๋ฐ, MySQL์ด ๋” ๊ฐ„๋‹จํ•ด๋ณด์ธ๋‹ค. Oracle WHERE rownum = n SELECT NAME FROM (S..
giraffe_
'SQL' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก