๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
IT์ž๊ฒฉ์ฆ ๊ณต๋ถ€/SQLD ์˜ˆ์ƒ๋ณต์›

[SQLD] 2024๋…„ SQLD 55ํšŒ ๊ธฐ์ถœ๋ณต์›

by yunamom 2025. 1. 4.
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” yunamom ์ž…๋‹ˆ๋‹ค :D

2024๋…„ 11์›” 17์ผ ์ผ์š”์ผ์— ์น˜๋ค„์ง„ ์ œ55ํšŒ SQLD ์‹œํ—˜ 1๊ณผ๋ชฉ, 2๊ณผ๋ชฉ ์ •๋‹ต์„ ํฌ์ŠคํŒ… ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป

 

*๋ฌธ์ œ ์ˆœ์„œ๋Š” ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋‹ต ์ž์ฒด๋ฅผ ์ ์–ด๋‘๊ฑฐ๋‚˜ ๋ฌธ์ œ๋งŒ ์ ์€ ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.


 

SQLD 55ํšŒ 1๊ณผ๋ชฉ


โ–  ๋ฌธ์ œ 1. ๋‚ด๋ถ€ ์Šคํ‚ค๋งˆ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (๋ชจ๋‘ ๊ณ ๋ฅด๊ธฐ )
 - (๋‚˜) (๋ฌผ๋ฆฌ์ ...)
 - (๋ผ) ์ง€๋ฌธ์ด ์ƒ๊ฐ์ด ์•ˆ๋‚˜๋Š”๋ฐ..์—ฌ๊ธฐ๋„ ๋‚ด๋ถ€ ์Šคํ‚ค๋งˆ ๋‚ด์šฉ ๊ฐ™๊ธด ํ–ˆ๋„ค์š”. 
     -> ๋ผ๋Š” ๊ฐœ๋…์ชฝ์œผ๋กœ ๋Œ“๊ธ€์˜ ์˜๊ฒฌ ๋ฐ˜์˜!
โ€‹
<์„ค๋ช…> ๊ฐ€์ด๋“œ์ฑ… P.24
์™ธ๋ถ€ - ๊ฐœ๋… - ๋‚ด๋ถ€ 
๋‚ด๋ถ€ ์Šคํ‚ค๋งˆ (๋ฌผ๋ฆฌ์  ์ €์žฅ๊ตฌ์กฐ)
 -> ๋‚ด๋ถ€ ๋‹จ๊ณ„์™€ ๋‚ด๋ถ€ ์Šคํ‚ค๋งˆ๋กœ ๊ตฌ์„ฑ๋จ. DB๊ฐ€ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ์ €์žฅ๋œ ํ˜•์‹ 
 -> ๋ฌผ๋ฆฌ์  ์žฅ์น˜์—์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์‹ค์ œ์ ์œผ๋กœ ์ €์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์„ ํ‘œํ˜„ํ•˜๋Š” ์Šคํ‚ค๋งˆ


โ–  ๋ฌธ์ œ 2. ์—”ํ„ฐํ‹ฐ๋ช…์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€?
 - ์•ฝ์–ด๋กœ ์‚ฌ์šฉํ•œ๋‹ค.
โ€‹
<์„ค๋ช…> ๊ฐ€์ด๋“œ์ฑ… P.45
์—”ํ„ฐํ‹ฐ๋ฅผ ๋ช…๋ช…ํ•˜๋Š” ์ผ๋ฐ˜์ ์ธ ๊ธฐ์ค€์€, ์šฉ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ํ‘œ๊ธฐ๋ฒ•์ด ๋‹ค ๊ทธ๋ ‡๋“ฏ์ด ์ฒซ ๋ฒˆ์งธ๋Š” ๊ฐ€๋Šฅํ•˜๋ฉด ํ˜„์—…
์—…๋ฌด์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์šฉ์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋‘ ๋ฒˆ์งธ๋Š” ๊ฐ€๋Šฅํ•˜๋ฉด ์•ฝ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ์„ธ ๋ฒˆ์งธ๋Š” ๋‹จ์ˆ˜ ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
๋„ค ๋ฒˆ์งธ๋Š” ๋ชจ๋“  ์—”ํ„ฐํ‹ฐ์—์„œ ์œ ์ผํ•˜๊ฒŒ ์ด๋ฆ„์ด ๋ถ€์—ฌ๋˜์–ด์•ผ ํ•œ๋‹ค. ๋‹ค์„ฏ ๋ฒˆ์งธ๋Š” ์—”ํ„ฐํ‹ฐ ์ƒ์„ฑ ์˜๋ฏธ๋Œ€๋กœ ์ด๋ฆ„์„ ๋ถ€์—ฌํ•œ๋‹ค.


โ–  ๋ฌธ์ œ 3. ๊ธฐ๋ณธ ์—”ํ„ฐํ‹ฐ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 
 - ๋‹ค๋ฅธ ์—”ํ„ฐํ‹ฐ๋กœ๋ถ€ํ„ฐ ์ฃผ์‹๋ณ„์ž๋ฅผ ์ƒ์†๋ฐ›๋Š”๋‹ค. 
 
<์„ค๋ช…> ๊ฐ€์ด๋“œ์ฑ… P.44
๊ธฐ๋ณธ์—”ํ„ฐํ‹ฐ๋ž€ ๊ทธ ์—…๋ฌด์— ์›๋ž˜ ์กด์žฌํ•˜๋Š” ์ •๋ณด๋กœ์„œ ๋‹ค๋ฅธ ์—”ํ„ฐํ‹ฐ์™€ ๊ด€๊ณ„์— ์˜ํ•ด ์ƒ์„ฑ๋˜์ง€ ์•Š๊ณ  ๋…๋ฆฝ์ ์œผ๋กœ ์ƒ์„ฑ์ด ๊ฐ€๋Šฅํ•˜๊ณ  
์ž์‹ ์€ ํƒ€ ์—”ํ„ฐํ‹ฐ์˜ ๋ถ€๋ชจ ์—ญํ• ์„ ํ•˜๊ฒŒ ๋œ๋‹ค. ๋‹ค๋ฅธ ์—”ํ„ฐํ‹ฐ๋กœ๋ถ€ํ„ฐ ์ฃผ์‹๋ณ„์ž๋ฅผ ์ƒ์†๋ฐ›์ง€ ์•Š๊ณ  ์ž์‹ ์˜ ๊ณ ์œ ํ•œ ์ฃผ์‹๋ณ„์ž๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.


โ–  ๋ฌธ์ œ 4. ์•„๋ž˜์˜ ์ •๊ทœํ™”๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? 
 - 2์ฐจ ์ •๊ทœํ™”
โ€‹
<๋ณด๊ธฐ> 
์ฃผ์‹๋ณ„์ž์˜ ์ปฌ๋Ÿผ๋‘๊ฐœ๋ฅผ ํ•˜๋‚˜์”ฉ ๋‚˜๋ˆ„์–ด ์ •๊ทœํ™”๋Š” ํ˜•ํƒœ๋กœ ํ…Œ์ด๋ธ” ๋ถ„๋ฆฌ 
 -> ์ผ๋ฐ˜์†์„ฑ์ด ์ฃผ์‹๋ณ„์ž์— ๋ถ€๋ถ„์ ์œผ๋กœ ์ข…์†๋˜๋Š” ํ˜„์ƒ์„ ํ•ด๊ฒฐ 


 โ–  ๋ฌธ์ œ 5. 1์ฐจ ์ •๊ทœํ˜•์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 
 - ์ผ๋ฐ˜์†์„ฑ์€ ์ฃผ์‹๋ณ„์ž ์ „์ฒด์— ์ข…์†์ ์ด๋‹ค.  


โ–  ๋ฌธ์ œ 6. ์‹๋ณ„์ž ๊ด€๊ณ„์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 
 - ๋ถ€๋ชจ ์—”ํ„ฐํ‹ฐ์™€ ์ž์‹ ์—”ํ„ฐํ‹ฐ์˜ ๊ด€๊ณ„๋Š” ํ•ญ์ƒ 1:1์˜ ๊ด€๊ณ„์ด๋‹ค 
 
<์„ค๋ช…> P.68
๋ถ€๋ชจ๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์†์„ฑ์„ ์ž์‹์—”ํ„ฐํ‹ฐ๊ฐ€ ๋ชจ๋‘ ์‚ฌ์šฉํ•˜๊ณ  ๊ทธ๊ฒƒ๋งŒ์œผ๋กœ ์ฃผ์‹๋ณ„์ž๋กœ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ๋ถ€๋ชจ์—”ํ„ฐํ‹ฐ์™€ ์ž์‹์—”ํ„ฐํ‹ฐ์˜ ๊ด€๊ณ„๋Š” 1:1์˜ ๊ด€๊ณ„๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค.
๋งŒ์•ฝ ๋ถ€๋ชจ๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์†์„ฑ์„ ํฌํ•จํ•˜์—ฌ ๋‹ค๋ฅธ ๋ถ€๋ชจ์—”ํ„ฐํ‹ฐ์—์„œ ๋น‹์€ ์†์„ฑ์„ ํฌํ•จํ•˜๊ฑฐ๋‚˜ ์Šค์Šค๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์†์„ฑ๊ณผ ํ•จ๊ป˜ ์ฃผ์‹๋ณ„์ž๋กœ ๊ตฌ์„ฑ๋˜๋Š” ๊ฒฝ์šฐ๋Š” 1:M ๊ด€๊ณ„๊ฐ€ ๋œ๋‹ค.


โ€‹โ–  ๋ฌธ์ œ 7. ๋ชจ๋‘ ์ˆ˜ํ–‰๋˜๊ฑฐ๋‚˜ ๋ชจ๋‘ ์ˆ˜ํ–‰๋˜์ง€ ์•Š์•„์•ผ ํ•œ๋‹ค๋Š” ํŠธ๋žœ์žญ์…˜์˜ ํŠน์ง•์€? 
 - ์›์ž์„ฑ 


โ–  ๋ฌธ์ œ 8. ๊ณ„์ธตํ˜• ๋ชจ๋ธ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 
 - ๊ฐœ์ฒด๊ฐ„์˜ ๊ด€๊ณ„๋Š” 1:1 ์ด๋‹ค.
<์ฐธ๊ณ  ์ž๋ฃŒ>
https://subsay.tistory.com/25


โ–  ๋ฌธ์ œ 9. ์•„๋ž˜์˜ ๋นˆ์นธ์— ์•Œ๋งž์€ ๊ฒƒ์€? 
<๊ทธ๋ฆผ> ๊ฐ€์ด๋“œ P.47 
 - ์—”ํ„ฐํ‹ฐ - ์ธ์Šคํ„ด์Šค - ์†์„ฑ - ์†์„ฑ๊ฐ’ 


โ–  ๋ฌธ์ œ 10. ์•„๋ž˜์˜ ์„ค๋ช…์— ์ ์ ˆํ•œ ๊ฒƒ์€? (๊ด€๊ณ„์ฐจ์ˆ˜ ์„ค๋ช…)
 - ๊ด€๊ณ„ ์ฐจ์ˆ˜ 
<๋ณด๊ธฐ> 
-> ๋‘ ๊ฐœ์˜ ์—”ํ„ฐํ‹ฐ๊ฐ„ ๊ด€๊ณ„์—์„œ ์ฐธ์—ฌ์ž์˜ ์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ
-> ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ๊ด€๊ณ„์ฐจ์ˆ˜ ํ‘œํ˜„๋ฐฉ๋ฒ•์€ 1:M, 1:1, M:N์ด๋‹ค.
โ€‹

SQLD 55ํšŒ 2๊ณผ๋ชฉโ€‹


โ–  ๋ฌธ์ œ 11.  ์„œ๋ธŒ์ฟผ๋ฆฌ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 

 - in ์ ˆ์€ ๋‹จ์ผํ–‰ ์„œ๋ธŒ์ฟผ๋ฆฌ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค

โ–  ๋ฌธ์ œ 12. DML ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? 

 - insert, update, delete

โ–  ๋ฌธ์ œ 13.  ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (dense_rank ๋ฌธ์ œ)

<SQL>
select ..
from ( select dense_rank() over(partition by ... desc .. ) 
โ€‹
 - dense_rank ๋ฌธ์ œ๋กœ ๋™์ผ ๋“ฑ์ˆ˜ ํ›„์—๋„ ์ˆœ์ฐจ์  ๋“ฑ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋ƒ„( 1,2,2,3,4 ... )
 - 1,2,2,1 ๊ฐ™์€ ํ˜•ํƒœ ๋‹ต

โ–  ๋ฌธ์ œ 14. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? ( Rollup + ์ผ๋ฐ˜์ปฌ๋Ÿผ ๋ฌธ์ œ) 

<SQL> 
INSERT INTO TAB1 VALUES('A',100);
INSERT INTO TAB1 VALUES('B',200);
INSERT INTO TAB1 VALUES('C',300);
INSERT INTO TAB1 VALUES('C',400);
โ€‹
select count(*)
from (
    select col1,sum(col2)
    from TAB1
    group by rollup(col1), col1
    )
where 1=1;
โ€‹
 - group by rollup(col1),col1 => group by col1,col1 union all group by (),col1 
 - group by col1 union all group by col1 ๊ณผ ๋™์ผํ•จ 
 - a,b,c ๋กœ ๊ตฌ๋ถ„๋˜๊ณ  ๊ฐ๊ฐ 3๊ฑด์”ฉ ๋˜์–ด 6๊ฑด

โ–  ๋ฌธ์ œ 15. ์•„๋ž˜์˜ SQL ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ณณ์œผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€?  

<SQL>
CREATE TABLE 1234_...   (1) 
 - (1) ํ…Œ์ด๋ธ”๋ช…์€ ์ˆซ์ž๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์—†๋‹ค.

โ–  ๋ฌธ์ œ 16. ์•„๋ž˜์˜ SQL ์ค‘ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ์€? ( ROLLUP ๊ณผ GROUPING SETS, GROUP BY ) 

 - rollup(a,b) ... --> ์ „์ฒด ์ง‘ํ•ฉ์ด ๋‚˜์˜ค๊ณ  ๋‚˜๋จธ์ง€๋Š” ์ „์ฒด์ง‘ํ•ฉ์ด ์—†์Œ

โ–  ๋ฌธ์ œ 17. ์•„๋ž˜์˜ SQL ๊ณผ ๋™์ผํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์€? ( ROLLUP ๊ณผ GROUPING SETS ์˜ ๋ณ€ํ™˜)

<SQL>
SELECT ..
FROM ..
GROUP BY grouping sets( rollup(a), b ) 
โ€‹
 - grouping sets (a,b, () )

โ–  ๋ฌธ์ œ 18. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (NULL ์—ฐ์‚ฐ ๋ฌธ์ œ)

<SQL>
SELECT COL1*2 + COL2*2 
FROM ...
<Data>
tab1   tab2
null     10
10        10
10        null
โ€‹
 - NULL*2 = NULL,  NULL ์ด ๋‘๊ฐœ ์ปฌ๋Ÿผ์—์„œ ๊ฐ๊ฐ ๋‚˜์˜ค๋Š” ํ˜•ํƒœ์˜ ๋‹ต
 - null, 40 , null

โ–  ๋ฌธ์ œ 19. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (NULL ๊ณผ ์ง‘๊ณ„์—ฐ์‚ฐ ๋ฌธ์ œ)

<SQL>
SELECT nvl( sum(c1) + sum(c2),0)
FROM ...
โ€‹
 - SUM(C1) ์—์„œ C1 ์˜ NULL ๊ฐ’์€ ์ œ๊ฑฐ๋˜๊ณ  SUM ์ด ๋จ.
 - ๊ฐ ์ปฌ๋Ÿผ์˜ SUM ์„ ํ•˜๊ณ  ๋‚˜์„œ ๋”ํ•œ ๊ฐ’์ด ๋จ

โ€‹โ–  ๋ฌธ์ œ 20. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (left , full, right ๊ฒฐ๊ณผ๊ฐ’)

<SQL>
T1 , T2 ํ…Œ์ด๋ธ”์— ๋Œ€ํ•œ T1 LEFT T2, T1 FULL T2 , T1 RIGHT T2 ๊ฒฐ๊ณผ
 
 - 3,5,3 ( FULL = LEFT OUTER JOIN UNION RIGHT OUTER JOIN )

โ–  ๋ฌธ์ œ 21. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (LEFT - LEFT - INNER JOIN ) 

<SQL> 
SELECT COUNT(*)
FROM T1
     LEFT OUTER T2
          LEFT OUTER T3
               INNER JOIN T4 
โ€‹
 - 1๊ฑด
 -> T1, T2 ์˜ LEFT OUTER JOIN ๊ฒฐ๊ณผ๋ฅผ T3 ์™€ LEFT OUTER JOIN (T2 ์ปฌ๋Ÿผ๊ณผ). ์ดํ›„ INNER JOIN (T4)

 


โ–  ๋ฌธ์ œ 22. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? 

<SQL> SELECT REGEXP_INSTR('12345678', '(123)(4(56)(78))',1, 1, 0, 'i', 2)  FROM DUAL; 
โ€‹
 - 4 (์œ„์˜ ๊ฒฐ๊ณผ์ž„. ์‹ค์ œ ๋ฌธ์ œ์™€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ)

โ–  ๋ฌธ์ œ 23. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? 

<SQL> 
SELECT REGEXP_SUBSTR('abcd', 'b\*c') AS COL1, REGEXP_SUBSTR('abcd', 'b*c') AS COL2 FROM dual
โ€‹
 - NULL, bc (์œ„์˜ ๊ฒฐ๊ณผ์ž„. ์‹ค์ œ ๋ฌธ์ œ์™€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ)

โ–  ๋ฌธ์ œ 24. ์•„๋ž˜์˜ ๊ณ„์ธตํ˜• ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” SQL ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์„ ๊ณ ๋ฅด์‹œ์˜ค 

<SQL - ๊ณ„์ธตํ˜• ์˜ˆ์‹œ>
SELECT  …
FROM … 
START WITH ๊ด€๋ฆฌ์ž๋ฒˆํ˜ธ IS NULL 
CONNECT BY PRIOR ( )  = (  ) 
โ€‹
<๊ฒฐ๊ณผ>
์ˆœ๋ฐฉํ–ฅ์œผ๋กœ ์‚ฌ์›๋ฒˆํ˜ธ-๊ด€๋ฆฌ์ž๋ฒˆํ˜ธ๊ฐ€ ๋‚˜์˜ค๋Š” ํ˜•ํƒœ
โ€‹
 - ์ˆœ๋ฐฉํ–ฅ์ด๋ฏ€๋กœ PRIOR (์‚ฌ์›๋ฒˆํ˜ธ) = (๊ด€๋ฆฌ์ž๋ฒˆํ˜ธ)

โ–  ๋ฌธ์ œ 25. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (ROW_NUMBER + ORDER BY) 

<SQL>
SELECT *
FROM (SELECT ROW_NUMBER() OVER(... DESC ) RN .... )
WHERE ..
ORDER BY RN DESC ;
โ€‹
 - DESC ๋กœ ๋œ ๋ฒˆํ˜ธ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ์ถœ๋ ฅ 
 - 2, 150 
   1, 40 ... (์ด๋Ÿฐ ํ˜•ํƒœ)

โ–  ๋ฌธ์ œ 26. ์•„๋ž˜์˜ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 

<์ง€๋ฌธ> ๋กœ๊ทธ์ธ ๊ด€๋ จ ์ฟผ๋ฆฌ์— ๋Œ€ํ•œ ์„ค๋ช… 
<๋ณด๊ธฐ>
1) 5์ผ๊ฐ„ ํ•˜๋ฃจ 3ํšŒ ๋กœ๊ทธ์ธ์„ ํ•œ๊ฒฝ์šฐ ์ฟผ๋ฆฌ๊ฒฐ๊ณผ๋Š” 15ํšŒ์ด๋‹ค 
2) ORDER BY ALIAS1, ALIAS2 SQL ์€ ์ •์ƒ ์ž‘๋™ํ•œ๋‹ค. 
 -> ์˜ค๋ผํด์—์„œ ALIAS ๋กœ ORDER BY ๊ฐ€๋Šฅ 
 - ๋“ฑ์˜ ๋ณด๊ธฐ๊ฐ€ ์žˆ๋Š” ๋ฌธ์ œ. ๋‹ต ๋ณด๊ธฐ๊ฐ€ ์ƒ๊ฐ๋‚˜์ง€ ์•Š์•„ ๋ฏธ์™„์„ฑ

โ–  ๋ฌธ์ œ 27. ALIAS ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€?

 - ์ปฌ๋Ÿผ ์•ž๋’ค๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. (์ปฌ๋Ÿผ ์•ž์— ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ)

โ–  ๋ฌธ์ œ 28. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? ( OR ์ ˆ์˜ ํ•ด์„ )

<SQL> 
SELECT ..
WHERE ๊ณ ๊ฐ๋ฒˆํ˜ธ = XX OR ๊ณ ๊ฐ๋ฒˆํ˜ธ = YY 
AND ..
AND ..
 
 - 5๊ฐœ ๋กœ์šฐ ( WHERE ๊ณ ๊ฐ๋ฒˆํ˜ธ= XX ์ธ ๊ฑด์ˆ˜ + OR ๋’ค ์กฐ๊ฑด๋“ค ๋งŒ์กฑํ•˜๋Š” ๊ฑด์ˆ˜ )

โ–  ๋ฌธ์ œ 29. ์•„๋ž˜์˜ ๊ฒฐ๊ณผ์ฒ˜๋Ÿผ 'ํ™๊ธธ๋™' ์˜ ์ž์‹์˜ ์ž์‹ ๋…ธ๋“œ๋ฅผ ์กฐํšŒํ•˜๋Š” ์ฟผ๋ฆฌ๋กœ ์•Œ๋งž์€ ๊ฒƒ์€? 
(๊ณ„์ธตํ˜• ์ฟผ๋ฆฌ๋ฅผ ์…€ํ”„ ์กฐ์ธ์œผ๋กœ ๋งŒ๋“œ๋Š” ํ˜•ํƒœ )

- SELECT C.EMPNO, C.ENAME, C.MGR
  FROM EMP A, EMP B, EMP C 
  WHERE A.ENAME = 'ํ™๊ธธ๋™'
  AND B.MGR = A.EMPNO
  AND C.MGR = B.EMPNO๏ผ›
โ€‹
-> ๋งŒ์•ฝ ์ž์‹ ๋…ธ๋“œ๋ฅผ ์กฐํšŒํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค 
- SELECT B.EMPNO, B.ENAME, B.MGR
  FROM EMP A, EMP B
  WHERE A.ENAME = 'ํ™๊ธธ๋™’
  AND B.MGR = A.EMPNO๏ผ›

โ–  ๋ฌธ์ œ 30. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ์€? ( ON, USING, NATURAL JOIN ์— ๋Œ€ํ•œ ๋ฌธ์ œ)  

- SELECT .. FROM A INNER JOIN B ON (DEPT_NO) 
 -> ON ์ ˆ์€ ํŠน์ • ์ปฌ๋Ÿผ๋ช…์ด ์™€์•ผ ํ•จ (์˜ค๋ฅ˜ ๊ตฌ๋ฌธ์ž„)
โ€‹
<์ฐธ๊ณ > 1๋ฒˆ์€ ์—๋Ÿฌ ๋ฐœ์ƒ 
1) SELECT * FROM HR.EMPLOYEES A INNER JOIN HR.DEPARTMENTS B ON (DEPARTMENT_ID) 
WHERE A.DEPARTMENT_ID = 90;
โ€‹
2) SELECT * FROM HR.EMPLOYEES A INNER JOIN HR.DEPARTMENTS B ON A.DEPARTMENT_ID = B.DEPARTMENT_ID 
WHERE A.DEPARTMENT_ID = 90;
โ€‹
3) SELECT *FROM HR.EMPLOYEES A INNER JOIN HR.DEPARTMENTS B USING (DEPARTMENT_ID) 
WHERE DEPARTMENT_ID = 90;
โ€‹
4) SELECT * FROM HR.EMPLOYEES A NATURAL JOIN HR.DEPARTMENTS B 
WHERE DEPARTMENT_ID = 90

โ–  ๋ฌธ์ œ 31. ๊ณ„์•ฝ์ด ์—†๋Š” ๊ณ ๊ฐ์„ ์ฐพ๋Š” SQL ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (EXIST ๊ตฌ๋ฌธ ๋ฌธ์ œ)

 - SELECT 
   FROM ... 
   WHERE NOT EXIST (SELECT 1 ... )

โ–  ๋ฌธ์ œ 32. ์•„๋ž˜์™€ ๊ฐ™์€ ERD ์—์„œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? 

<ERD>
๊ณ„์•ฝ, ๊ณ ๊ฐ , ์ƒ์„ธ๋‚ด์šฉ 
 - SELECT COUNT(*) ... ๊ณ ๊ฐ/์ƒ์„ธ๋‚ด์šฉ ์กฐ์ธ์€ ์ƒ์„ธ๋‚ด์šฉ์˜ ๊ฑด์ˆ˜์™€ ๊ฐ™๋‹ค.

โ–  ๋ฌธ์ œ 33. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? ( UNION ALL + ALIAS ์„ ํƒ ๊ธฐ์ค€) 

<SQL> 
SELECT COL1 AS AAB, COL2 AS BBA 
FROM ..
UNIN ALL 
SELECT COL1 AS BBA, COL2 AS AAB 
FROM ..
โ€‹
 - ์ปฌ๋Ÿผ๋ช… AAB,BBA ๋กœ ์‹œ์ž‘๋˜๋Š” ROW

โ–  ๋ฌธ์ œ 34. 3ํšŒ ์ด์ƒ ์ฃผ๋ฌธํ•œ ๊ณ ๊ฐ์„ ์ฐพ๋Š” SQL ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (์ž๊ฒฉ๊ฒ€์ • 40๋ฒˆ ๋ฌธ์ œ์™€ ๊ฑฐ์˜ ๋™์ผ)

 - HAVING COUNT(๊ตฌ๋งค๋ฒˆํ˜ธ) >= 3

โ–  ๋ฌธ์ œ 35. ์•„๋ž˜์˜ SQL ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๋ถ€๋ถ„์€? 

<SQL>
CREATE TABLE SQLD_55_34_01 
(
    COL1 VARCHAR2(50),
    COL2 NUMBER,
    COL3 VARCHAR2(50),
    CONSTRAINT PK_01 PRIMARY KEY (COL1)
);
โ€‹
CREATE TABLE SQLD_55_34_02 
(
    COL4 VARCHAR2(50),
    COL5 NUMBER,
    COL1 VARCHAR2(50),
    CONSTRAINT PK_02 PRIMARY KEY (COL4),
    CONSTRAINT FK_02_01 FOREIGN KEY (COL1) REFERENCES SQLD_55_34_01(COL1)
);
1)INSERT INTO SQLD_55_34_01 VALUES ('A',100,'๊ฐ€');
2)INSERT INTO SQLD_55_34_02 VALUES ('02_A',100,NULL);
3)INSERT INTO SQLD_55_34_02 VALUES ('02_B',200,'A');
4)UPDATE SQLD_55_34_02 SET COL1 = 'B' WHERE COL4 = '02_A';
โ€‹
 - 4๋ฒˆ ์—๋Ÿฌ
-> ORA-02291: integrity constraint (SQL_QQYONNQTOWOSMXTURQWJCUGZU.FK_02_01) violated - parent key not found ORA-06512: at "SYS.DBMS_SQL", line 1721
โ€‹

โ–  ๋ฌธ์ œ 36. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ถœ๋ ฅ๋˜๋Š” ๋ถ€๋ถ„์„ ์•Œ๋งž๊ฒŒ ๊ณ ๋ฅธ ๊ฒƒ์€? (SAVEPOINT ์™€ ROLLBACK) 

<SQL>
(๊ฐ€) SQL1...
       SAVEPOINT A; 
(๋‚˜) SQL2...
       SAVEPOINT B; 
(๋‹ค) SQL3...
       ROLLBACK SAVEPOINT A;
(๋ผ) SQL4...
(๋งˆ) SQL5...
โ€‹
 - ๊ฐ€, ๋ผ, ๋งˆ

โ–  ๋ฌธ์ œ 37. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? ( ์˜ค๋ผํด์˜ null ์ด ํฌํ•จ๋œ ORDER BY ๊ฒฐ๊ณผ)

 - order by.. desc ์˜ null ๊ธฐ๋ณธ ์˜ต์…˜์€ first ๋กœ ๋งจ ์œ„๋กœ ํ‘œ์‹œ๋จ 
   -> order by : default - asc nulls last / desc nulls first

โ–  ๋ฌธ์ œ 38. ROW LIMITING ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 

<๋ณด๊ธฐ>
...
<์˜ณ์€ ์„ค๋ช…> 
1) OFFSET offset : ๊ฑด๋„ˆ๋›ธ ํ–‰์˜ ๊ฐœ์ˆ˜๋ฅผ ์ง€์ •ํ•œ๋‹ค.
2) FETCH : ๋ฐ˜ํ™˜ํ•  ํ–‰์˜ ๊ฐœ์ˆ˜๋‚˜ ๋ฐฑ๋ถ„์œจ์„ ์ง€์ •ํ•œ๋‹ค.
3) ONLY : ์ง€์ •๋œ ํ–‰์˜ ๊ฐœ์ˆ˜๋‚˜ ๋ฐฑ๋ถ„์œจ๋งŒํผ ํ–‰์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
4) WITH TIES : ๋งˆ์ง€๋ง‰ ํ–‰์— ๋Œ€ํ•œ ๋™์ˆœ์œ„๋ฅผ ํฌํ•จํ•ด์„œ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
โ€‹
 - WITH TIES (์œ„์˜ ๋ณด๊ธฐ๋Š” ๋งž๋Š” ์„ค๋ช…๋งŒ ์žˆ๋Š” ์˜ˆ์ œ)
   -> ์ฒซ๋ฒˆ์งธ ํ–‰์— ๋Œ€ํ•œ ๋™์ˆœ์œ„๋ผ๊ณ  ๋ณด๊ธฐ์— ๋‚˜์™”๋‹ค๊ณ  ํ•จ. ONLY ์˜๊ฒฌ๋„ ๋‹ค์ˆ˜ ์žˆ์Œ

โ–  ๋ฌธ์ œ 39. ์ง‘๊ณ„ ํ•จ์ˆ˜์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 

 - COUNT(expr) : Null ์„ ํฌํ•จํ•˜์—ฌ count ๊ฐ€ ๋จ ( * ๋ฅผ ์ œ์™ธํ•œ ํ‘œํ˜„์‹์ผ ๊ฒฝ์šฐ null ์€ ์ œ์™ธ๋จ)

โ–  ๋ฌธ์ œ 40. ์•„๋ž˜์˜ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ•˜๋Š” SQL ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (Window Function ๊ตฌํ˜„ ๋ฌธ์ œ)

<๋ฐ์ดํ„ฐ ๊ฒฐ๊ณผ>
๋ฐ์ดํ„ฐ ... ์ „์ฒด ํ•ฉ๊ณ„ ... ๋ถ€์„œ ํ•ฉ๊ณ„ 
โ€‹
 - SELECT .... SUM(...) OVER(), SUM(...) OVER(PARTITION BY DEPT... )

โ–  ๋ฌธ์ œ 41. SQL Set operator ์˜ Union all ๊ณผ ๊ฐ™์€ ๊ฒƒ์€? 

 - UNION + INTERSECT

โ–  ๋ฌธ์ œ 42. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? ( NULL ๋ฐ 0 ์œผ๋กœ ๋‚˜๋ˆ„๊ธฐ)

<SQL>
1) SELECT COL1/COL2 FROM TAB WHERE ... ( COL1 = 0 , COL2 = 300) 
2) SELECT COL1/COL2 FROM TAB WHERE ... ( COL1 = 300 , COL2 = 0) 
3) SELECT COL1/COL2 FROM TAB WHERE ... ( COL1 = 100 , COL2 = NULL)
โ€‹
 - 0, ERROR, NULL 
    -> 0, ERROR( ORA-01476: divisor is equal to zero ) , NULL

 


โ–  ๋ฌธ์ œ 43. ํ…Œ์ด๋ธ”์˜ ๊ตฌ์กฐ๋ฅผ ์œ ์ง€ํ•œ์ฒด ๋กœ์šฐ๋งŒ ์‚ญ์ œํ•˜๋Š” ๋ช…๋ น์–ด๋Š”? 

 - DELETE, TRUNCATE

โ–  ๋ฌธ์ œ 44. ์•„๋ž˜์˜ SQL ์˜ ๊ฒฐ๊ณผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? ( LIKE ์— ๋Œ€ํ•œ ๋ฌธ์ œ)

<ํ…Œ์ด๋ธ”> 
... ๋ฌผ๋ฆฌํ•™ ..
... ...ํ•™ ..
<SQL> 
SELECT ..
FROM ..
WHERE ๊ณผ๋ชฉ LIKE '%ํ•™' 
โ€‹
 - 2๊ฐœ (ํ•™์œผ๋กœ ๋๋‚˜๋Š” ๋‘๊ฐœ ๊ณผ๋ชฉ ๋‚˜์˜ด)

โ–  ๋ฌธ์ œ 45. NULL ์ด ์•„๋‹Œ ๊ฒƒ์€ ์ฐพ๋Š” SQL ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? 

 - IS NOT NULL

โ–  ๋ฌธ์ œ 46. ์•„๋ž˜์˜ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„ ํ…Œ์ด๋ธ”์— ์ง์žฅ์šฐํŽธ๋ฒˆํ˜ธ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ• ๋ ค๊ณ  ํ•  ๋•Œ ์ ์ ˆํ•œ ๋ช…๋ น์–ด๋Š”? 

 - ALTER TABLE xxxx ADD (OFFI_POST_NUMBER VARCHAR2(80) )๏ผ›
    -> ์ปฌ๋Ÿผ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ช…๋ น์–ด

 


โ–  ๋ฌธ์ œ 47. ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ๊ตฌํ˜„ํ•ด์ฃผ๋Š” ํ‚ค๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€?  

 - ์™ธ๋ž˜ํ‚ค 
    -> ๊ฐœ์ฒด ๋ฌด๊ฒฐ์„ฑ (PK), ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ (FK), ๋„๋ฉ”์ธ ๋ฌด๊ฒฐ์„ฑ (Check)

โ–  ๋ฌธ์ œ 48. ๋ฌด๊ฒฐ์„ฑ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? 

 - ๋„์„œ๊ด€ ํ…Œ์ด๋ธ”์— (2,'...') ์‚ฝ์ž… : ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ์œ„๋ฐฐ. ๊ฐœ์ฒด ๋ฌด๊ฒฐ์„ฑ ์œ„๋ฐฐ (PK)
   -> ๊ฐœ์ฒด ๋ฌด๊ฒฐ์„ฑ (PK), ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ (FK), ๋„๋ฉ”์ธ ๋ฌด๊ฒฐ์„ฑ (Check)

โ–  ๋ฌธ์ œ 49. ์•„๋ž˜์˜ SQL ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ์œผ๋กœ ์ ์ ˆํ•œ ๊ฒƒ์€? (between ์กฐ๊ฑด์ ˆ ๋ฌธ์ œ)

<SQL> 
SELECT..
FROM..
WHERE COL1 BETWEEN ๋‚ ์งœ(XXXX) AND ๋‚ ์งœ(YYYY)
โ€‹
 - COL1 > ๋‚ ์งœ(XXXX) AND COL1 < ๋‚ ์งœ(YYYY)

โ–  ๋ฌธ์ œ 50. ์•„๋ž˜์˜ SQL ์— ๋Œ€ํ•œ ์„ค๋ช…์œผ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ์€? ( IN ์ ˆ ์„ค๋ช…) 

<SQL>
SELECT ...
FROM ..
WHERE DEPT IN (SELECT DEPT 
                               FROM .. 
                               WHERE EMPNM IN (JOHN, SMITH) ) 
     
 - JOHN ์ด ๋‘๋ช…์ผ ๊ฒฝ์šฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค .. ๋ผ๋Š” ๋น„์Šทํ•œ??๋Š๋‚Œ์˜.. (IN ์ ˆ์€ DISTINCT ๋กœ ๊ฐ’์„ ์ •๋ฆฌํ•˜์—ฌ ๋น„๊ตํ•จ)

 

์ถœ์ฒ˜: ๋ฐ์ดํ„ฐ ์ „๋ฌธ๊ฐ€ ํฌ๋Ÿผ

300x250

์ฝ”๋“œ