λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Data Base/MySQL

MySQL 18λ²ˆμ§Έμˆ˜μ—…

by μ½”λ”©ν•˜λŠ” λΆ•μ–΄ 2021. 2. 8.
λ°˜μ‘ν˜•

9-11) μž₯ν•™κΈˆ μˆ˜λ Ήμ΄μ•‘μ΄ 500,000μ›μ—μ„œ 2,000,000원 사이에 ν¬ν•¨λ˜μ§€ μ•ŠλŠ” 각 ν•™μƒμ˜ ν•™λ²ˆμ„ 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no

-> from fee

-> group by stu_no

-> having not(sum(ifnull(jang_total, 0)) between 500000 and 2000000);

​

​

9-12) μž…ν•™λ…„λ„κ°€ 2002λ…„λΆ€ν„° 2006λ…„κΉŒμ§€ μž…ν•™ν•œ ν•™μƒμ˜ ν•™λ²ˆκ³Ό μž…ν•™λ…„λ„λ₯Ό 좜λ ₯ν•˜λΌ.​

A)

mysql> select stu_no, fee_year

-> from fee

-> where fee_div='Y' and fee_enter is not null

-> and fee_year between 2012 and 2018;

​

​

9-13) μΆœμƒλ…„λ„κ°€ 1998λ…„, 2000λ…„, 2002년에 νƒœμ–΄λ‚œ ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름, μΆœμƒλ…„λ„λ₯Ό 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name, substring(birthday,1,4)

-> from student

-> where substring(birthday,1,4) in (1998,2000,2002);

​

​

9-14) λ‚˜μ΄κ°€ 19μ„ΈλΆ€ν„° 23μ„Έ 사이인 ν•™μƒμ˜ ν•™λ²ˆμ„ 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no

-> from student

-> where year(now())-substring(birthday,1,4)+1 between 19 and 23;

​

​

9-16) μ„œμšΈκ΄‘μ—­μ‹œμ™€ 경기도에 κ±°μ£Όν•˜μ§€ μ•ŠλŠ” ν•™μƒμ˜ 번호, 이름, 우편번호λ₯Ό 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name, post_no

-> from student

-> where not(address like 'μ„œμšΈνŠΉλ³„μ‹œ%' or address like '경기도%');

​

​

9-17) μ˜λ¬Έμ΄λ¦„μ΄ 문자 'Kim'으둜 μ‹œμž‘ν•˜λŠ” 각 ν•™μƒμ˜ ν•™λ²ˆλ΄ 이름을 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name

-> from student

-> where stu_ename like 'Kim%';

​

​

9-18) μ˜λ¬Έμ΄λ¦„μ΄ 13문자둜 κ΅¬μ„±λœ 각 ν•™μƒμ˜ 이름과 ν•™λ²ˆμ„ 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name

-> from student

-> where length(rtrim(stu_ename)) = 13;

​

​

9-19) μ˜λ¬Έμ΄λ¦„μ΄ 13문자 μ΄μƒμœΌλ‘œ κ΅¬μ„±λœ 각 ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름을 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name

-> from student

-> where length(rtrim(stu_ename)) > 13;

​

​

9-20) ν•™μƒμ˜ μ˜λ¬Έμ΄λ¦„μ΄ μ•žμ—μ„œ 4번째 λ¬Έμžκ°€ 'g'인 ν•™μƒμ˜ 각 ν•™λ²ˆκ³Ό 이름을 좜λ ₯ν•˜λΌβ€‹.

A)

mysql> select stu_no, stu_name

-> from student

-> where substring(stu_ename,4,1) = 'g';

​

​

9-21) λ‹€μŒ SELECT λͺ…령문에 μžˆλŠ” 쑰건은 μ •λ‹Ήν•˜λ‹€ or μ •λ‹Ήν•˜μ§€λͺ»ν•˜λ‹€ ?

select * from student where stu_name is null;

​

A) quaryμƒμœΌλ‘œλŠ” λ¬Έμ œκ°€ μ—†λ‹€. κ·ΈλŸ¬λ‚˜ stu_nameμ—λŠ” null 값이 올 μˆ˜κ°€ μ—†μŒ...

​

​​

9-22) 적어도 ν•œ 번 이상 μž₯ν•™κΈˆμ„ 지급 받은 ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름을 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name

-> from student

-> where stu_no in

-> (select stu_no from fee where jang_total > 0);

​

mysql> select distinct s.stu_no, stu_name

-> from student s, fee f

-> where s.stu_no=f.stu_no and jang_total is not null;

​

​

9-23) 1,000,000 μ΄μƒμ˜ μž₯ν•™κΈˆμ„ 적어도 ν•œ 번 이상 지급받은 ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름을 좜λ ₯ν•˜λΌ.

A)

mysql> select distinct s.stu_no, stu_name

-> from student s, fee f

-> where s.stu_no=f.stu_no and jang_total > 1000000;

​

​

9-24) 적어도 ν•œ 번 이상 μž₯ν•™κΈˆμ„ 지급 λ°›μ•˜κ³  동아리에 κ°€μž…ν•˜μ§€ μ•Šμ€ ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름을 좜λ ₯ν•˜λΌ.

A)

mysql> select distinct s.stu_no, stu_name

-> from student s, fee f

-> where s.stu_no=f.stu_no and jang_total is not null

-> and s.stu_no not in (select stu_no from circle);

​

​

9-26) 남학생 쀑 λ‚˜μ΄κ°€ κ°€μž₯ λ§Žμ€ ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름, μΆœμƒλ…„λ„λ₯Ό 좜λ ₯ν•˜λΌβ€‹.

A)

mysql> select stu_no, stu_name, substring(birthday,1,4) 'μΆœμƒλ…„λ„'

-> from student

-> where birthday <= all

-> (select birthday from student where gender=1);

​

​

9-28) 적어도 ν•œ κ³Όλͺ© 이상 μˆ˜κ°•μ‹ μ²­μ„ ν•œ ν•™μƒμ˜ 이름과 ν•™λ²ˆμ„ 좜λ ₯ν•˜λΌ.

A)

mysql> select distinct stu_name, s.stu_no

-> from student s, attend a

-> where s.stu_no=a.stu_no;

​

​

9-29) ν•™λ²ˆ 20191007번의 등둝년도, ν•™κΈ°, λ“±λ‘λ‚ μ§œμ™€ 이름을 좜λ ₯ν•˜λΌ.

A)

mysql> select fee_year, fee_term, fee_date, s.stu_name

-> from fee f, student s

-> where s.stu_no=f.stu_no and f.stu_no='20191007';

​

​

9-30) μˆ˜κ°•μ‹ μ²­μ„ ν•˜μ˜€μœΌλ‚˜ 보관성적이 μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν•™μƒμ˜ ν•™λ²ˆκ³Ό μˆ˜κ°•λ…„λ„, ν•™κΈ°, μˆ˜κ°•κ³Όλͺ©μ„ 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, att_year, att_term, sub_name

-> from attend a, subject s

-> where a.sub_code=s.sub_code

-> and stu_no not in (select stu_no from score);

​

​

9-31) 동아리 ν…Œμ΄λΈ”μ—μ„œ λ™μ•„λ¦¬μ˜ 회μž₯의 ν•™λ²ˆκ³Ό 이름, 동아리 λͺ…을 좜λ ₯ν•˜λΌ.

A)

mysql> select stu_no, stu_name, cir_name from circle where president=0;

​

​

9-32) 동아리에 μ†Œμ†λ˜μ§€ μ•Šμ€ ν•™μƒμ˜ ν•™λ²ˆκ³Ό 이름을 좜λ ₯ν•˜λΌβ€‹

A)

mysql> select stu_no, stu_name

-> from student

-> where not exists

-> (select * from circle where stu_no = s.stu_no);

 

λ°˜μ‘ν˜•

'Data Base > MySQL' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

MySQL 20λ²ˆμ§Έμˆ˜μ—…  (0) 2021.02.09
MySQL 19λ²ˆμ§Έμˆ˜μ—…  (0) 2021.02.08
MySQL 17λ²ˆμ§Έμˆ˜μ—…  (0) 2021.02.08
MySQL 16λ²ˆμ§Έμˆ˜μ—…  (0) 2021.02.08
MySQL 15λ²ˆμ§Έμˆ˜μ—…  (0) 2021.02.08

λŒ“κΈ€