<μ°μ΅λ¬Έμ >
8-3) κ° νμμ λνμ¬ μκ°μ μ² κ³Όλͺ©μ½λ, μκ°νμ μ λνλ΄μ΄λΌ.
A)
mysql> select stu_no, sub_code, att_point from attend where att_div = 'y';
β
β
β
8-4) μ₯νκΈμ λ°μ νμμ νλ²κ³Ό μ΄λ¦μ λνλ΄μ΄λΌ.
A)
mysql> select distinctβ s.stu_no, stu_name
→ from student s, fee fβ
→ where s.stu_no = f.stuβ_no and ifnull(jang_total, 0) > 0;
β
β
β
βΆ SELECT λͺ λ Ήλ¬Έ : WHEREμ
β
1. κ΄κ³ μ°μ°μλ₯Ό μ¬μ©νλ 쑰건
ββ
μμ 9-1) μ±λ³μ΄ μ¬μμΈ νμμ νλ²κ³Ό μ΄λ¦, μ±λ³, μλ μμΌμ μΆλ ₯νλΌ.
A)
mysql> select stu_no, stu_name, gender, birthday
-> from student
-> where gender = 2 or gender = 4 or gender = 6;
β
β
μμ 9-2) μΌκ° νμλ€μ νλ²κ³Ό μ΄λ¦μ μΆλ ₯νλΌ.
A)
mysql> select stu_no, stu_name
-> from student
-> where juya = 'μΌ';
β
β
μμ 9-3) νλ²μ΄ 20191008μΈ νμμ νλ²κ³Ό μ΄λ¦μ λνλ΄μ΄λΌ.
A)
mysql> select stu_no, stu_name
-> from student
-> where stu_no = '20191008';
β
β
μμ 9-4) ν΄λν°μ κ°μ§κ³ μλ νμμ νλ²κ³Ό μ΄λ¦, ν΄λν°λ²νΈλ₯Ό λνλ΄μ΄λΌ.
A)
mysql> select stu_no, stu_name, mobile
-> from student
-> where mobile = mobile;
-μ¬κΈ°μ mobile = mobileμ λμΌν mobileμ΄ μ‘΄μ¬νλ©΄ λͺ¨λ νμ΄ μΆλ ₯λ κ²μ΄κ³ mobileμ΄ NULLκ°μΈ κ²½μ°μλ μΆλ ₯λμ§ μλλ€.
ββ
β
μμ 9-5) 2000λ μ΄μ μ μΆμν μ¬νμμ νλ², μ΄λ¦, μλ μμΌμ μΆλ ₯νλΌ.
A)
1.
mysql> select stu_no, stu_name, gender, birthday
-> from student
-> where gender = 2 and substring(birthday, 1, 4) < 2000;
β
2.
mysql> select stu_no, stu_name, gender, birthday
-> from student
-> where (gender = 2 or gender = 4 or gender = 6) and substring(birthday, 1, 4) < 2000;
β μ°μ° μ°μ μμ
1. and
2. or
κ·Έλ¬λ―λ‘ κΌ κ΄νΈλ‘ λ¬Άμ΄μ£Όμ.
β
ββ
μμ 9-6) κ²½μΈμ§μμ κ±°μ£Όνλ νμμ νλ²κ³Ό μ΄λ¦, μ§ μ νλ²νΈλ₯Ό λνλ΄μ΄λΌ. (λ¨, μ§ μ νμ μ§μλ²νΈ 02λ μμΈ κ±°μ£Όμμ΄κ³ 031μ κ²½κΈ°λ κ±°μ£Όμμ΄λ€. μ§μ νκ° μλ κ²½μ°λ μ μΈνλ€.)
A)
mysql> select stu_no, stu_name, concat(tel1, '-', tel2, '-', tel3) "μ§μ ν"
-> from student
-> where tel1 = '02' or tel1 = '031';
β
β
μμ 9-7) 2000λ λμ νμ΄λμ§ μμ νμμ νλ², μ΄λ¦, μλ μμΌμ λνλ΄μ΄λΌ.β
A)
mysql> select stu_no, stu_name, birthday
-> from student
-> where substring(birthday, 1, 4) <> 2000;
- <> : κ°μ§ μλ€λ λ»
ββ
β
μμ 9-8) μ±λ³μ΄ λ¨μμ΄κ±°λ 1999λ μ μΆμν νμμ νλ², μ΄λ¦, μ±λ³, μλ μμΌμ λνλ΄μ΄λΌ. κ·Έλ¬λ 1999λ λμ μΆμν λ¨νμμ μ μΈνλ€.
A)
mysql> select stu_no, stu_name, gender, birthday from student
-> where (gender = 1 or substring(birthday, 1, 4) = 1999)
-> andβ not (gender = 1 and substring(birthday, 1, 4) = 1999);
β
β
β
βΆ BETWEEN μ°μ°μ
β
μμ 9-9) νμ¬ λμ΄κ° 20μ΄λΆν° 23μ΄κΉμ§ νμμ νλ²κ³Ό μ΄λ¦, λμ΄λ₯Ό μΆλ ₯νλΌ. (λ¨, AGES λ·°ν μ΄λΈμ μ¬μ©νλ€.)
A)
1.
mysql> select stu_no, stu_name, age
-> from ages
-> where age >= 20
-> and age <= 23;
β
2.
mysql> select stu_no, stu_name, age
-> from ages
-> where age between 20 and 23;
β
β
μμ 9-10) μΆμμ°λκ° 1997λ λΆν° 2000λ μ¬μ΄μ νμ΄λ νμμ νλ²κ³Ό μ΄λ¦, μΆμλ λλ₯Ό μΆλ ₯νλΌ. λ¨, μΆμλ λ μ€λ¦μ°¨μμΌλ‘ μΆλ ₯νλΌ.
A)
mysql> select stu_no, stu_name, birthday
-> from student
-> where substring(birthday, 1, 4) between 1997 and 2000
-> order by birthday;
β
β
β
βΆ IN μ°μ°μ
β
μμ 9-11) μ°νΈλ²νΈκ° 01066, 01901, 06305μ ν΄λΉλλ κ° νμμ νλ², μ΄λ¦, μ°νΈλ²νΈλ₯Ό μΆλ ₯νλΌ.
βA)
1.
mysql> select stu_no, stu_name, post_no
-> from student
-> where post_no = '01066'
-> or post_no = '01901'
-> or post_no = '06305';
β
2.
mysql> select stu_no, stu_name, post_no
-> from student
-> where post_no in('01066', '01901', '06305');
β
β
μμ 9-12) 1996, 1997, 2001λ μ μΆμν κ° νμμ νλ²κ³Ό μ΄λ¦, μλ μμΌμ μΆλ ₯νλΌ.
A)
mysql> select stu_no, stu_name, birthday
-> from student
-> where substring(birthday, 1, 4) in(1996, 1997, 2001);
β
β
β
βΆ LIKE μ°μ°μ
LIKE μ°μ°μλ νΉλ³ν ν¨ν΄μ΄λ λ§μ€ν¬λ₯Ό κ°μ§λ μμμΉ κ°μ μ νν λ μ¬μ©λλ€.β
β
μμ 9-13) μλ¬Έμ΄λ¦μ΄ λ¬Έμ Kλ‘ μμνλ νμμ νλ²κ³Ό μ΄λ¦, μλ¬Έμ΄λ¦μ λνλ΄μ΄λΌ.
A)
mysql> select stu_no, stu_name, stu_ename
-> from student
-> where stu_ename like 'K%';
β
β
μμ 9-14) μλ¬Έμ΄λ¦μ 맨 λμ λ¬Έμ gλ₯Ό κ°μ§κ³ μλ νμμ νλ²κ³Ό μ΄λ¦μ λνλ΄μ΄λΌ.
A)
mysql> select stu_no, stu_ename
-> from student
-> where stu_ename like '%g';
-νΉλ³ν μλ―Έλ₯Ό λνλ΄λ λ λ€λ₯Έ κΈ°νΈλ λ°μ€ κΈ°νΈ(_) μ΄λ€. λ°μ€ κΈ°νΈλ LIKE μ°μ°μμ κ°μ΄ μ¬μ©λλ©΄ μ νν ν λ¬Έμλ₯Ό λνλΈλ€.
β
ββ
μμ 9-15) μλ¬Έμ΄λ¦μ λμμ λλ²μ§Έ λ¬Έμκ° iμΈ νμμ νλ²κ³Ό μ΄λ¦μ λνλ΄μ΄λΌ.
A)
mysql> select stu_no, stu_ename
-> from student
-> where stu_ename like '%i_';
β
β
μμ 9-16) μλ¬Έμ΄λ¦μ΄ λ¬Έμ Kλ‘ μμνμ§μλ νμμ νλ²κ³Ό μ΄λ¦μ λνλ΄μ΄λΌ.
A)
mysql> select stu_no, stu_ename
-> from student
-> where not (stu_ename like 'K%');
'Data Base > MySQL' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
MySQL 18λ²μ§Έμμ (0) | 2021.02.08 |
---|---|
MySQL 17λ²μ§Έμμ (0) | 2021.02.08 |
MySQL 15λ²μ§Έμμ (0) | 2021.02.08 |
MySQL 14λ²μ§Έμμ (0) | 2021.02.08 |
MySQL 13λ²μ§Έμμ (0) | 2021.02.08 |
λκΈ