[Oracle] Solution to puzzles

Joy🌱·2023λ…„ 1μ›” 11일
0

🧩 Coding Challenges

λͺ©λ‘ 보기
11/20
post-thumbnail
post-custom-banner

🧩 WHERE절과 μ—¬λŸ¬ μ—°μ‚°μžλ₯Ό ν™œμš©ν•˜μ—¬ SQL 쿼리 짜기

Q1

πŸ’β€β™€οΈ 좘 κΈ°μˆ λŒ€ν•™κ΅μ˜ ν•™κ³Ό 이름과 계열을 ν‘œμ‹œν•˜μ„Έμš”.
(단, 좜λ ₯ ν—€λ”λŠ” "ν•™κ³Ό λͺ…", "계열"둜 ν‘œμ‹œ)

🚩 Example Output 63 rows selected

ν•™κ³Ό λͺ…계열
κ΅­μ–΄κ΅­λ¬Έν•™κ³ΌμΈλ¬Έμ‚¬νšŒ
κ΅­μ–΄κ΅­λ¬Έν•™κ³ΌμΈλ¬Έμ‚¬νšŒ
μ˜μ–΄μ˜λ¬Έν•™κ³ΌμΈλ¬Έμ‚¬νšŒ
. . . . . .. . . . . .
λ””μžμΈ ν•™κ³Όμ˜ˆμ²΄λŠ₯
μ²΄μœ‘ν•™κ³Όμ˜ˆμ²΄λŠ₯
SELECT
        DEPARTMENT_NAME "ν•™κ³Ό λͺ…"
    ,   CATEGORY "계열"
    FROM TB_DEPARTMENT;

Q2

πŸ’β€β™€οΈ ν•™κ³Όμ˜ ν•™κ³Ό 정원을 λ‹€μŒκ³Ό 같은 ν˜•νƒœλ‘œ 화면에 좜λ ₯ν•˜μ„Έμš”.

🚩 Example Output 63 rows selected

학과별 정원
κ΅­μ–΄κ΅­λ¬Έν•™κ³Όμ˜ 정원은 20λͺ… μž…λ‹ˆλ‹€.
μ˜μ–΄μ˜λ¬Έν•™κ³Όμ˜ 정원은 36λͺ… μž…λ‹ˆλ‹€.
. . . . . .
λ””μžμΈν•™κ³Όμ˜ 정원은 32λͺ… μž…λ‹ˆλ‹€.
μ²΄μœ‘ν•™κ³Όμ˜ 정원은 24λͺ… μž…λ‹ˆλ‹€.
SELECT
        DEPARTMENT_NAME || '의 정원은 ' || CAPACITY || 'λͺ… μž…λ‹ˆλ‹€.' "학과별 정원"
    FROM TB_DEPARTMENT;

Q3

πŸ’β€β™€οΈ "κ΅­μ–΄κ΅­λ¬Έν•™κ³Ό" 에 λ‹€λ‹ˆλŠ” 여학생 쀑 ν˜„μž¬ νœ΄ν•™μ€‘μΈ 여학생을 μ°Ύμ•„λ‹¬λΌλŠ” μš”μ²­μ΄ λ“€μ–΄μ™”μŠ΅λ‹ˆλ‹€. λˆ„κ΅¬μΌκΉŒμš”?
(κ΅­λ¬Έν•™κ³Όμ˜ 'ν•™κ³Όμ½”λ“œ'λŠ” ν•™κ³Ό ν…Œμ΄λΈ”(TB_DEPARTMENT)을 μ‘°νšŒν•΄μ„œ μ°Ύμ•„ 내도둝 ν•©μ‹œλ‹€.)

🚩 Example Output 1 rows selected

STUDENT_NAME
ν•œμˆ˜ν˜„
SELECT
        STUDENT_NAME
    FROM TB_STUDENT
    WHERE DEPARTMENT_NO = '001'
    AND ABSENCE_YN = 'Y'
    AND STUDENT_SSN LIKE '_______2%';

Q4

πŸ’β€β™€οΈ λ„μ„œκ΄€μ—μ„œ λŒ€μΆœ λ„μ„œ μž₯κΈ° μ—°μ²΄μž 듀을 μ°Ύμ•„ 이름을 κ²Œμ‹œν•˜κ³ μž ν•©λ‹ˆλ‹€. κ·Έ λŒ€μƒμžλ“€μ˜ ν•™λ²ˆμ΄ λ‹€μŒκ³Ό 같을 λ•Œ λŒ€μƒμžλ“€μ„ μ°ΎλŠ” μ μ ˆν•œ SQL ꡬ문을 μž‘μ„±ν•˜μ„Έμš”.

  • A513079, A513090, A513091, A513110, A513119

🚩 Example Output 5 rows selected

STUDENT_NAME
μ΄κ²½ν™˜
. . . . . .
홍경희
SELECT
        STUDENT_NAME
    FROM TB_STUDENT
    WHERE STUDENT_NO IN ('A513079', 'A513090', 'A513091', 'A513110', 'A513119');

Q5

πŸ’β€β™€οΈ μž…ν•™μ •μ›μ΄ 20 λͺ… 이상 30 λͺ… μ΄ν•˜μΈ ν•™κ³Όλ“€μ˜ ν•™κ³Ό 이름과 계열을 좜λ ₯ν•˜μ„Έμš”.

🚩 Example Output 24 rows selected

DEPARTMENT_NAMECATEGORY
κ΅­μ–΄κ΅­λ¬Έν•™κ³ΌμΈλ¬Έμ‚¬νšŒ
μ‚¬ν•™κ³ΌμΈλ¬Έμ‚¬νšŒ
. . . . . .. . . . . .
μ‚°μ—…λ””μžμΈν•™κ³Όμ˜ˆμ²΄λŠ₯
μ²΄μœ‘ν•™κ³Όμ˜ˆμ²΄λŠ₯
SELECT
        DEPARTMENT_NAME
    ,   CATEGORY
    FROM TB_DEPARTMENT
    WHERE CAPACITY BETWEEN 20 AND 30;

Q6

πŸ’β€β™€οΈ 좘 κΈ°μˆ λŒ€ν•™κ΅λŠ” 총μž₯을 μ œμ™Έν•˜κ³  λͺ¨λ“  κ΅μˆ˜λ“€μ΄ μ†Œμ† ν•™κ³Όλ₯Ό 가지고 μžˆμŠ΅λ‹ˆλ‹€. 그럼 좘 κΈ°μˆ λŒ€ν•™κ΅ 총μž₯의 이름을 μ•Œμ•„λ‚Ό 수 μžˆλŠ” SQL λ¬Έμž₯을 μž‘μ„±ν•˜μ„Έμš”.

🚩 Example Output 1 rows selected

PROFESSOR_NAME
μž„ν•΄μ •
SELECT
        PROFESSOR_NAME
    FROM TB_PROFESSOR
    WHERE DEPARTMENT_NO IS NULL;

Q7

πŸ’β€β™€οΈ ν˜Ήμ‹œ μ „μ‚°μƒμ˜ 착였둜 ν•™κ³Όκ°€ μ§€μ •λ˜μ–΄ μžˆμ§€ μ•Šμ€ 학생이 μžˆλŠ”μ§€ ν™•μΈν•˜κ³ μž ν•©λ‹ˆλ‹€. μ–΄λ– ν•œ SQL λ¬Έμž₯을 μ‚¬μš©ν•˜λ©΄ 될 것인지 μž‘μ„±ν•˜μ„Έμš”.

SELECT
        *
    FROM TB_STUDENT
    WHERE DEPARTMENT_NO IS NULL;

Q8

πŸ’β€β™€οΈ μˆ˜κ°•μ‹ μ²­μ„ ν•˜λ €κ³  ν•©λ‹ˆλ‹€. μ„ μˆ˜κ³Όλͺ© μ—¬λΆ€λ₯Ό 확인해야 ν•˜λŠ”λ°, μ„ μˆ˜κ³Όλͺ©μ΄ μ‘΄μž¬ν•˜λŠ” κ³Όλͺ©λ“€μ€ μ–΄λ–€ κ³Όλͺ©μΈμ§€ κ³Όλͺ©λ²ˆν˜Έλ₯Ό μ‘°νšŒν•΄λ³΄μ„Έμš”.

🚩 Example Output 6 rows selected

CLASS_NO
C0405500
. . . . . .
C3221500
SELECT
        CLASS_NO
    FROM TB_CLASS
    WHERE PREATTENDING_CLASS_NO IS NOT NULL;

Q9

πŸ’β€β™€οΈ 좘 λŒ€ν•™μ—λŠ” μ–΄λ–€ 계열(CATEGORY)듀이 μžˆλŠ”μ§€ μ‘°νšŒν•΄λ³΄μ„Έμš”.

🚩 Example Output 5 rows selected

CATEGORY
곡학
. . . . . .
μžμ—°κ³Όν•™
SELECT
        DISTINCT CATEGORY
    FROM TB_DEPARTMENT;

πŸ“Œ Ref.

* DISTINCT : 쀑볡 된 컬럼 값을 μ œκ±°ν•˜μ—¬ μ‘°νšŒν•˜λ©°, SELECTμ ˆμ— λ”± ν•œ 번만 μ‚¬μš© κ°€λŠ₯

Q10

πŸ’β€β™€οΈ 02 ν•™λ²ˆ μ „μ£Ό κ±°μ£Όμžλ“€μ˜ λͺ¨μž„을 λ§Œλ“€λ €κ³  ν•©λ‹ˆλ‹€. νœ΄ν•™ν•œ μ‚¬λžŒλ“€μ€ μ œμ™Έν•œ μž¬ν•™μ€‘μΈ ν•™μƒλ“€μ˜ ν•™λ²ˆ, 이름, 주민번호λ₯Ό 좜λ ₯ν•˜λŠ” ꡬ문을 μž‘μ„±ν•˜μ„Έμš”.

🚩 Example Output 11 rows selected

STUDENT_NOSTUDENT_NAMESTUDENT_SSN
A213066윀영우841122-1128518
A217005κ³ μˆ˜ν˜„821119-2122202
. . . . . .. . . . . .. . . . . .
A211375μ΅œν—ˆν˜„841102-1154425
SELECT
        STUDENT_NO
    ,   STUDENT_NAME
    ,   STUDENT_SSN
    FROM TB_STUDENT
    WHERE ENTRANCE_DATE LIKE '02%'
    AND STUDENT_ADDRESS LIKE '%μ „μ£Ό%'
    AND ABSENCE_YN = 'N';
profile
Tiny little habits make me
post-custom-banner

0개의 λŒ“κΈ€