πβ κ³Όλͺ©μ ν ν μ΄λΈ(TB_CLASS_TYPE)μ μλμ κ°μ λ°μ΄ν°λ₯Ό μ λ ₯νμΈμ.
INSERT
INTO TB_CLASS_TYPE
(
CLASS_TYPE_NO, CLASS_TYPE_NAME
)
VALUES
(
01, 'μ 곡νμ'
);
INSERT
INTO TB_CLASS_TYPE
(
CLASS_TYPE_NO, CLASS_TYPE_NAME
)
VALUES
(
02, 'μ 곡μ ν'
);
INSERT
INTO TB_CLASS_TYPE
(
CLASS_TYPE_NO, CLASS_TYPE_NAME
)
VALUES
(
03, 'κ΅μνμ'
);
INSERT
INTO TB_CLASS_TYPE
(
CLASS_TYPE_NO, CLASS_TYPE_NAME
)
VALUES
(
04, 'κ΅μμ ν'
);
INSERT
INTO TB_CLASS_TYPE
(
CLASS_TYPE_NO, CLASS_TYPE_NAME
)
VALUES
(
05, 'λ
Όλ¬Έμ§λ'
);
πβ μΆ κΈ°μ λνκ΅ νμλ€μ μ λ³΄κ° ν¬ν¨λμ΄ μλ νμμΌλ°μ 보 ν μ΄λΈμ λ§λ€κ³ μ ν©λλ€. μλ λ΄μ©μ μ°Έκ³ νμ¬ μ μ ν SQL λ¬Έμ μμ±νμΈμ. (μλΈμΏΌλ¦¬λ₯Ό μ΄μ©νμΈμ.)
CREATE TABLE TB_νμμΌλ°μ 보 (
νλ²
, νμμ΄λ¦
, μ£Όμ
)
AS
SELECT
STUDENT_NO
, STUDENT_NAME
, STUDENT_ADDRESS
FROM TB_STUDENT;
πβ κ΅μ΄κ΅λ¬Ένκ³Ό νμλ€μ μ 보λ§μ΄ ν¬ν¨λμ΄ μλ νκ³Όμ 보 ν μ΄λΈμ λ§λ€κ³ μ ν©λλ€. μλ λ΄μ©μ μ°Έκ³ νμ¬ μ μ ν SQLλ¬Έμ μμ±νμΈμ. (ννΈ : λ°©λ²μ λ€μν¨, μμ κ» μμ±νμΈμ.)
CREATE TABLE TB_κ΅μ΄κ΅λ¬Ένκ³Ό (
νλ²
, νμμ΄λ¦
, μΆμλ
λ
, κ΅μμ΄λ¦
)
AS
SELECT
STUDENT_NO
, STUDENT_NAME
, 19 || SUBSTR(STUDENT_SSN , 1, 2)
, PROFESSOR_NAME
FROM TB_STUDENT S
JOIN TB_PROFESSOR ON (COACH_PROFESSOR_NO = PROFESSOR_NO)
JOIN TB_DEPARTMENT D ON (S.DEPARTMENT_NO = D.DEPARTMENT_NO)
WHERE D.DEPARTMENT_NAME = 'κ΅μ΄κ΅λ¬Ένκ³Ό';
πβ ν νκ³Όλ€μ μ μμ 10% μ¦κ°μν€κ² λμμ΅λλ€. μ΄μ μ¬μ©ν SQL λ¬Έμ μμ±νμΈμ. (λ¨, λ°μ¬λ¦Όμ μ¬μ©νμ¬ μμμ μλ¦Ώμλ μκΈ°μ§ μλλ‘ ν©λλ€.)
UPDATE
TB_DEPARTMENT
SET CAPACITY = ROUND(CAPACITY + (CAPACITY * 0.1), -1);
πβ νλ² A413042 μΈ λ°κ±΄μ° νμμ μ£Όμκ° "μμΈμ μ’ λ‘ꡬ μμΈλ 181-21 "λ‘ λ³κ²½λμλ€κ³ ν©λλ€. μ£Όμμ§λ₯Ό μ μ νκΈ° μν΄ μ¬μ©ν SQL λ¬Έμ μμ±νμΈμ.
UPDATE
TB_STUDENT
SET STUDENT_ADDRESS = 'μμΈμ μ’
λ‘ꡬ μμΈλ 181-21'
WHERE STUDENT_NO = 'A413042'
AND STUDENT_NAME = 'λ°κ±΄μ°';
πβ μ£Όλ―Όλ±λ‘λ²νΈ 보νΈλ²μ λ°λΌ νμμ 보 ν μ΄λΈμμ μ£Όλ―Όλ²νΈ λ·μ리λ₯Ό μ μ₯νμ§ μκΈ°λ‘ κ²°μ νμ΅λλ€. μ΄ λ΄μ©μ λ°μν μ μ ν SQL λ¬Έμ₯μ μμ±νμΈμ. (μ. 830530-2124663 ==> 830530 )
UPDATE
TB_STUDENT
SET STUDENT_SSN = SUBSTR(STUDENT_SSN, 1, 6);
πβ μνκ³Ό κΉλͺ ν νμμ 2005 λ 1 νκΈ°μ μμ μ΄ μκ°ν 'νΌλΆμ리ν' μ μκ° μλͺ»λμλ€λ κ²μ λ°κ²¬νκ³ λ μ μ μ μμ²νμ΅λλ€. λ΄λΉ κ΅μμ νμΈ λ°μ κ²°κ³Ό ν΄λΉ κ³Όλͺ©μ νμ μ 3.5 λ‘ λ³κ²½ν€λ‘ κ²°μ λμμ΅λλ€. μ μ ν SQL λ¬Έμ μμ±νμΈμ.
UPDATE
TB_GRADE
SET POINT = 3.5
WHERE TERM_NO = '200501'
AND (STUDENT_NO, CLASS_NO) = (SELECT
STUDENT_NO
, CLASS_NO
FROM TB_GRADE
JOIN TB_STUDENT S USING (STUDENT_NO)
JOIN TB_CLASS USING (CLASS_NO)
JOIN TB_DEPARTMENT D ON (S.DEPARTMENT_NO = D.DEPARTMENT_NO)
WHERE STUDENT_NAME = 'κΉλͺ
ν'
AND CLASS_NAME = 'νΌλΆμ리ν'
AND DEPARTMENT_NAME = 'μνκ³Ό');
π¬ Overall Comment
* DMLλ¬Έ μμμ JOINμ μ¬μ©νμ§ λͺ» νλ€λ κ²μ μκ²ν΄μ€ λ¬Ένμ΄μλ€.
μ΄λ΄ λλ μλΈμΏΌλ¦¬ μμμ μ¬μ©νλ λ°©ν₯μΌλ‘ κ°μΌκ² λ€.
πβ μ±μ ν μ΄λΈ(TB_GRADE)μμ ν΄νμλ€μ μ±μ νλͺ©μ μ κ±°νμΈμ.
COMMIT;
DELETE
FROM TB_GRADE
WHERE STUDENT_NO IN (SELECT
STUDENT_NO
FROM TB_GRADE
JOIN TB_STUDENT USING (STUDENT_NO)
WHERE ABSENCE_YN = 'Y');
π¬ Overall Comment
* WHEREμ μμ λ€μ€ν μλΈμΏΌλ¦¬λ₯Ό μ¬μ©ν λ '='μ΄ μλ 'IN'μ μ¬μ©ν΄μΌνλ€λ κ²μ μκΈ°μμΌμ€
λ¬Ένμ΄μλ€. μμμ μΌλ‘ νμ΄ μ¬λ¬ κ°μ΄λ©΄ '=(κ°λ€)'λ₯Ό μ¬μ©νλ©΄ μ μ νμ§ μμΌλ μ κΈ°μ΅ν΄λμ!