Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- ์ฝ๋ฉ
- database
- JavaScript
- ์ฅํธ์์ค
- ๋ผํ๋ผ์ค์๋ง๋
- ์ค๋ผํด
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- html
- ์นํผ๋ธ๋ฆฌ์ฑ
- K๋ฐฐํฐ๋ฆฌ๋ ๋ณผ๋ฃจ์
- ํ๋ก๊ทธ๋๋ฐ
- ๋ฐ์ํ
- ๊น๋ฏธ๊ฒฝ์๋งํ์์
- ๊ฐ๋ฐ
- K๋ฐฐํฐ๋ฆฌ
- ๊นํ๋จ
- Python
- Java
- ์ฑ
- ์นํ์ด์ง๋ง๋ค๊ธฐ
- ์ํ
- ComputerScience
- ๋ ์
- ๋ง์ผ๋ด๊ฐ์ธ์์๋ค์์ฐ๋ค๋ฉด
- ์๋ฐ์คํฌ๋ฆฝํธ
- css
- ์๋ฐ
- ํ์ด์ฌ
- ์ปดํจํฐ๊ณผํ
- ๊น๋ฏธ๊ฒฝ
Archives
- Today
- Total
JiYoung Dev ๐ฅ
[database ๊ณ ๊ธ] ๊ณ์ธต ์ฟผ๋ฆฌ (2023.08.09) ๋ณธ๋ฌธ
๊ณ์ธต ์ฟผ๋ฆฌ ํ์ฉ์ ๋ฉ๋ด, ๊ฒ์ํ์ ๋๊ธ, ๋๋๊ธ์ ๋ง๋ค ์ ์์
์์ ์ฟผ๋ฆฌ
SELECT ๋ฉ๋ดID
, ์์๋ฉ๋ดID
, ๋ฉ๋ด์ด๋ฆ
, LEVEL
, LPAD(' ' , ( LEVEL -1 ) * 2 , ' ' ) || ๋ฉ๋ด์ด๋ฆ
FROM ๋ฉ๋ด
WHERE 1=1 -- WHERE ์กฐ๊ฑด์ด ์์ผ๋ฉด ๋ฐ๋ก ์์จ๋ ๋จ
START WITH ์์๋ฉ๋ดID IS NULL
CONNECT BY NOCYCLE ์์๋ฉ๋ดID = PRIOR ๋ฉ๋ดID
ORDER SIBLINGS BY ๋ฉ๋ดID ;
์
ํ ์กฐ์ธ(SELF JOIN)
SELECT *
FROM ๋ฉ๋ด A, ๋ฉ๋ด B
WHERE A.์์๋ฉ๋ดID = B.๋ฉ๋ดID;
-- ์
ํ์กฐ์ธ (๊ณ์ธต ์ฟผ๋ฆฌ๊ฐ ์๋ ์์ ์ ๊ณ์ธต์ ๊ตฌํํ๊ธฐ ์ํด ์ฌ์ฉ)
๋๋๊ธ ๊ตฌํ
SELECT ๋๊ธID
, ์์๊ธ
, ์์ฑ๊ธ
, CASE WHEN ์์ฑ๊ธ IS NULL THEN
( SELECT ๊ฒ์๋ฌผ๋ด์ฉ
FROM ๊ฒ์ํ
WHERE ๊ฒ์๊ธID = ์์๊ธ )
ELSE LPAD('ใ
ฃ-' , LEVEL*2 , ' ') || ์์ฑ๊ธ
END
AS ๊ณ์ธต์ฟผ๋ฆฌ๊ฒฐ๊ณผ
, LEVEL
FROM ๋๊ธ
START WITH ์์ฑ๊ธ IS NULL
CONNECT BY PRIOR ๋๊ธID = ์์๊ธ ;
'full stack > database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[database ๊ณ ๊ธ] db ์ค๊ณ (2023.08.10) (0) | 2023.08.10 |
---|---|
[database ๊ณ ๊ธ] ํ๋ก์์ (2023.08.09 ~ 10) (0) | 2023.08.09 |
[database ๊ณ ๊ธ] ์ธ๋ฑ์ค (2023.08.09) (0) | 2023.08.09 |
[database ๊ณ ๊ธ] ์๋์ฐ ํจ์ (2023.08.09) (0) | 2023.08.09 |
[database ๊ณ ๊ธ] ์งํฉ์ฐ์ฐ์ (2023.08.08) (0) | 2023.08.08 |