<μ°μ΅λ¬Έμ > (λ°μ΄ν° λ³κ²½λ¬Έμ λΌμ κ²°κ³Όλ μΊ‘μ³μν¨)
β
16-1) νμ¬ νλ μ΄ 3νλ μ΄λ©΄ 2019λ 1νκΈ°μ λ±λ‘ ν μ΄λΈμ μμ λ£(fee_price)μ 100000μ, λ±λ‘κΈμ΄μ‘(fee_total), λ©λΆμ΄μ‘(fee_pay)μ κ°κ° 100000μμ κ°μ°νμ¬ λ°μ΄ν° κ°μ λ³κ²½νλΌ.
A)
mysql> update fee
-> set fee_price = fee_price + 100000,
-> fee_total = fee_total + 100000,
-> fee_pay = fee_pay + 100000
-> where fee_year = 2019 and fee_term = 1 and stu_no in
-> (select stu_no from student where grade = 3);
β
β
16-2) λ±λ‘ ν μ΄λΈμμ μ νκΈ(fee_enter), μμ λ£(fee_price)λ₯Ό 5% μ¦κ°μν€κ³ λ±λ‘κΈμ΄μ‘(fee_total), λ©λΆ μ΄μ‘(fee_pay)λ μ¦κ°μμΌ λ³κ²½νλΌ.
A)
mysql> update fee
-> set fee_enter = fee_enter * 1.05,
-> fee_price = fee_price * 1.05,
-> fee_total = ifnull(fee_enter, 0) + fee_price,
-> fee_pay = fee_total - ifnull(jang_total , 0);
β
β
16-3) νλ² 20161001λ²μ΄ '2016'λ λμ μκ° μ μ²ν λͺ¨λ λ°μ΄ν°λ₯Ό μμ νλΌ.
A)
mysql> delete from attend
-> where stu_no = '20161001'
-> and att_year = '2016';
β
β
16-4) λμ리μ κ°μ ν νμμ μκ°μ μ² λ°μ΄ν°λ₯Ό μμ νλΌ.
A)
mysql> delete from attend
-> where stu_no in
-> (select stu_no from circle);
β
β
16-5) "μ νλ" νμκ³Ό κ°μ λμμ μ΄κ³ μλ λͺ¨λ νμμ μμ νλΌ. κ·Έλ¬λ "μ νλ" νμμ μ μΈμν¨λ€.
A)
mysql> delete from student
-> where substring(address, 1, 2) =
-> (select * from (select substring(address, 1, 2) from student where stu_name = 'μ νλ') as a)
-> and stu_name <> 'μ νλ';
β
β
ββ
βΆ μΈλ±μ€μ μ¬μ©
β
create index μΈλ±μ€μ΄λ¦ on ν μ΄λΈμ΄λ¦ (μ΄, ...);
β
drop index μΈλ±μ€μ΄λ¦ on ν μ΄λΈμ΄λ¦
ββ
β
β
<μ°μ΅λ¬Έμ >
β
17-2) νμ ν μ΄λΈ(STUDENT)μμ μλ μμΌμ μ μΌνμ§ μμ μΈλ±μ€λ₯Ό μμ±νλΌ.β
A)
mysql> create index stu_idx_birth on student(birthday);
β
β
17-3) νμ ν μ΄λΈ(STUDENT)μμ μ΄λ¦κ³Ό μλ μμΌμ μ‘°ν©νμ¬ μ μΌν μΈλ±μ€λ₯Ό μμ±νλΌ.
A)
mysql> create unique index sidx_name_birth on student(stu_name, birthday);
β
β
17-4) 17-2μ 17-3μμ μμ±ν μΈλ±μ€λ₯Ό μμ νλΌ.
A)
mysql> drop index stu_idx_birth on student;
mysql> drop index sidx_name_birth on student;
β
β
β
βΆ λ·°(VIEW)
β
*λ·°μ μμ±
β
μμ 18-1) STUDENT ν μ΄λΈλ‘λΆν° λͺ¨λ νμμ νλ²κ³Ό νλ , λ°μ κ°μ§κ³ μλ λ·° ν μ΄λΈ(V_CLASS)μ μμ±νλΌ.
A)
mysql> create view v_class as
-> select stu_no, grade, class
-> from student;
β
β
μμ 18-2) λ±λ‘ν νμμ νλ²κ³Ό λ±λ‘λ λμ λν λ·° ν μ΄λΈμ μμ±νλΌ.
A)
mysql> create view v_feeyear as
-> select stu_no, fee_year
-> from fee
-> where fee_year is not null;
β
β
μμ 18-3) μ¬νμμ νλ²κ³Ό μ΄λ¦, μ±λ³, μ νλ λ, μλ , μ, μΌ, λμ΄μ λν λ·° ν μ΄λΈ(V_AGES)μ μμ±νλΌ.
A)
mysql> create view V_AGES as
-> select stu_no, stu_name, gender,
-> substring(stu_no, 1, 4) 'IBHAK_YEAR',
-> substring(birthday, 1, 4) 'B_YEAR',
-> substring(birthday, 5, 2) 'B_MONTH',
-> substring(birthday, 7, 2) 'B_DATE',
-> year(now()) - substring(birthday, 1, 4) + 1 'AGE'
-> from student;
β
β
μμ 18-4) μ¬νμ μ€ 20μΈ μ΄μμΈ μ¬νμμ νλ², μ΄λ¦, μ±λ³, μΆμλ λ, λμ΄λ₯Ό μΆλ ₯νλΌ.
A)
mysql> select stu_no, stu_name, gender, b_year, age
-> from V_AGES
-> where age > 19 and gender in (2, 4, 6);
β
β
μμ 18-5) μ¬νμ μ€ 21μΈμ ν΄λΉνλ νμμ μ±λ μ νμ¬λ₯Ό μν λͺ λ¨μ μΆλ ₯νλΌ. λ¨, μΆλ ₯νμμ νκ³Ό, νλ , νλ², μ΄λ¦, μλ , μ, μΌ, λμ΄λ₯Ό μΆλ ₯νλΌ.
A)
mysql> select dept_code "νκ³Όμ½λ", grade "νλ ", s.stu_no "νλ²", s.stu_name "μ΄λ¦",
-> b_year "λ ", b_month "μ", b_date "μΌ", age "λμ΄"
-> from student s, V_AGES v
-> where s.stu_no = v.stu_no and age = 21
-> order by 1, 2, 3;
'Data Base > MySQL' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
MySQL λ¬Έμ (0) | 2021.02.09 |
---|---|
MySQL 25λ²μ§Έμμ (0) | 2021.02.09 |
MySQL 23λ²μ§Έμμ (0) | 2021.02.09 |
MySQL 22λ²μ§Έμμ (0) | 2021.02.09 |
MySQL 21λ²μ§Έμμ (0) | 2021.02.09 |
λκΈ