메뉴 건너뛰기

조회 수 134 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

 

 

-- 적어도 한 번 이상 등록한 학생의 학번과 이름을 출력하라 

-- (o)

select DISTINCT s.stu_no, s.stu_name

from student s, fee f

where s.stu_no = f.stu_no;

-- (o)

select stu_no,stu_name

from student

where EXISTS

(select *

 from fee 

 where student.stu_no=stu_no);

-- 학생중에 동아리의 등급이 일반 회원인 학생의 학번과 이름, 주민번호를 출력하라 

-- (o)

select s.stu_no, s.stu_name, s.id_num 

from student s, circle c

where s.stu_no= c.stu_no

and c.president=2;

-- (o)

select stu_no, stu_name, id_num

from student

where stu_no in

(select stu_no

from circle

where president =2);

-- 두번 이상 장학금을 지급 받은 학생중 장학금액이 학기별로 서로 다른 경우의 학생의 학번을 출력하라 

-- (o)

select stu_no,count(jang_code)

from fee

group by stu_no

HAVING count(jang_code)>=2;

-- (o)

select DISTINCT stu_no

from fee f

where stu_no in

(select stu_no

from fee

where jang_total <> f.jang_total);

-- 학적 테이블에서 동아리 "java길라잡이"에 가입하지 않은 학생의 학번과 이름, 주야구분을 출력하라 

-- (x) ??

select stu_no, stu_name, juya

from student 

where sut_no not in  

(select stu_no

 from circle 

 where cir_name='java길라잡이');

-- (o)

select stu_no, stu_name, juya

from student

where 'java길라잡이' <> 

all (select cir_name

from circle

where stu_no= student.stu_no);

 

 

-- 학적테이블에서 학번이 가장 큰 3명의 학번을 내림차순으로 출력하라 

-- (x)

select stu_no

from student

order by stu_no desc;

-- (o) ???????????

 

select stu_no

from student s1

where 3 >

 

(select count(*)

from student s2

where (s1.stu_no < s2.stu_no))

order by stu_no desc;

 

-- (x) 

select s2.stu_no, count(*)

from student s1 ,student s2

group by s1.stu_no

having s1.stu_no < s2.stu_no

;

 

 

 

-- 학적 테이블에서 학번이 가장 작은 학번을 가진 3명의 학생을 오름차순으로 출력하라 

 -- ???

select stu_no

from student s1

where 3 > 

 

(select count(*) 

from student s2

where (s1.stu_no > s2.stu_no))

order by stu_no;

 

 

-- 등록테이블에서 장학금을 지급 받은 학생 중 가장 작은 장학금액을 지급 받은 학생 8명의 학번, 

-- 장학금 총액을 출력하라 

 

 

select DISTINCT stu_no, jang_total

from fee f1

where 8 >

(select count(*)

from fee f2

where (f1.jang_total > f2.jang_total)

 

)order by f1.jang_total desc;

 

-- 

-- 등록테이블에서 등록한 학생 중에서 납부 총액이 가장 큰 학생을 포함한 3명의 학번, 납부총액을

-- 출력하라 

-- 

select stu_no, fee_pay

from fee f1

where 3 >

 

(select count(*)

from fee f2

where f1.fee_pay < f2.fee_pay) 

 

)

 

-- 20061011 학생이 가입한 동아리에 소속된 모든 학생의 학번과 이름을 출력하라 

-- 

-- (x)

select stu_no , stu_name

from student s 

where cir_name =

(select c.cir_name 

from circle c

where s.stu_no = c.stu_no

and c.stu_no = 20061011);

 

-- (o)

select s1.stu_no, s1.stu_name

from student s1  , circle c1

where s1.stu_no=c1.stu_no 

and c1.cir_name =

(select cir_name 

from circle 

where stu_no = 20061011);

 

 

-- (o)??

 

select stu_no , stu_name

from student s 

where not exists

 

(select *

from circle c

where c.stu_no = 20061011

and not EXISTS

 

(SELECT *

from circle c2

where c.cir_name = c2.cir_name

and s.stu_no = c2.stu_no)

);

 

 

 

 

-- 적어도 한 번 장학금을 받은 학생에 대하여 학번, 등록년도, 학기, 장학금액 중 가장 큰 장학금액, 등록일자를 출력하라 

-- 

-- (x)

select stu_no, fee_year, fee_term, jang_total, fee_date

from fee

group by stu_no

having jang_total = max(jang_total);

 

 

-- (o) ??

select stu_no, fee_year, fee_term, jang_total, fee_date

from fee f1

where jang_total=

(select max(jang_total)

from fee f2

where f1.stu_no = f2.stu_no);

 

 

 

-- 2007년 1학기에 등록한 학생이 같은 연도, 학기에 수강 신청한 학생의 학번과 등록년도, 등록학기,

-- 수강신청년도, 학기를 출력하라 (중복된 자료를 제거하기 위해서 distinct를 사용)

 

-- (x)

select DISTINCT f1.stu_no, f1.fee_year, f1.fee_term, a1.att_year, a1.att_term

from fee f1, attend a1

where f1.stu_no=a1.stu_no

and f1.fee_year = 2007

and f1.fee_term =1;

 

 

 

select DISTINCT f1.stu_no, f1.fee_year, f1.fee_term, a1.att_year, a1.att_term

from fee f1, attend a1

where f1.stu_no=a1.stu_no

and f1.fee_year = 2007

and f1.fee_term =1

and f1.fee_year = a1.att_year

and f1.fee_term = a1.att_term

;

 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 
-- 적어도 한 번 이상 등록한 학생의 학번과 이름을 출력하라 
-- (o)
select DISTINCT s.stu_no, s.stu_name
from student s, fee f
where s.stu_no = f.stu_no;
-- (o)
select stu_no,stu_name
from student
where EXISTS
(select *
 from fee 
 where student.stu_no=stu_no);
-- 학생중에 동아리의 등급이 일반 회원인 학생의 학번과 이름, 주민번호를 출력하라 
-- (o)
select s.stu_no, s.stu_name, s.id_num 
from student s, circle c
where s.stu_no= c.stu_no
and c.president=2;
-- (o)
select stu_no, stu_name, id_num
from student
where stu_no in
(select stu_no
from circle
where president =2);
-- 두번 이상 장학금을 지급 받은 학생중 장학금액이 학기별로 서로 다른 경우의 학생의 학번을 출력하라 
-- (o)
select stu_no,count(jang_code)
from fee
group by stu_no
HAVING count(jang_code)>=2;
-- (o)
select DISTINCT stu_no
from fee f
where stu_no in
(select stu_no
from fee
where jang_total <> f.jang_total);
-- 학적 테이블에서 동아리 "java길라잡이"에 가입하지 않은 학생의 학번과 이름, 주야구분을 출력하라 
-- (x) ??
select stu_no, stu_name, juya
from student 
where sut_no not in  
(select stu_no
 from circle 
 where cir_name='java길라잡이');
-- (o)
select stu_no, stu_name, juya
from student
where 'java길라잡이' <> 
all (select cir_name
from circle
where stu_no= student.stu_no);
 
 
-- 학적테이블에서 학번이 가장 큰 3명의 학번을 내림차순으로 출력하라 
-- (x)
select stu_no
from student
order by stu_no desc;
-- (o) ???????????
 
select stu_no
from student s1
where 3 >
 
(select count(*)
from student s2
where (s1.stu_no < s2.stu_no))
order by stu_no desc;
 
-- (x) 
select s2.stu_no, count(*)
from student s1 ,student s2
group by s1.stu_no
having s1.stu_no < s2.stu_no
;
 
 
 
-- 학적 테이블에서 학번이 가장 작은 학번을 가진 3명의 학생을 오름차순으로 출력하라 
 -- ???
select stu_no
from student s1
where 3 > 
 
(select count(*
from student s2
where (s1.stu_no > s2.stu_no))
order by stu_no;
 
 
-- 등록테이블에서 장학금을 지급 받은 학생 중 가장 작은 장학금액을 지급 받은 학생 8명의 학번, 
-- 장학금 총액을 출력하라 
 
 
select DISTINCT stu_no, jang_total
from fee f1
where 8 >
(select count(*)
from fee f2
where (f1.jang_total > f2.jang_total)
 
)order by f1.jang_total desc;
 
-- 
-- 등록테이블에서 등록한 학생 중에서 납부 총액이 가장 큰 학생을 포함한 3명의 학번, 납부총액을
-- 출력하라 
-- 
select stu_no, fee_pay
from fee f1
where 3 >
 
(select count(*)
from fee f2
where f1.fee_pay < f2.fee_pay) 
 
)
 
-- 20061011 학생이 가입한 동아리에 소속된 모든 학생의 학번과 이름을 출력하라 
-- 
-- (x)
select stu_no , stu_name
from student s 
where cir_name =
(select c.cir_name 
from circle c
where s.stu_no = c.stu_no
and c.stu_no = 20061011);
 
-- (o)
select s1.stu_no, s1.stu_name
from student s1  , circle c1
where s1.stu_no=c1.stu_no 
and c1.cir_name =
(select cir_name 
from circle 
where stu_no = 20061011);
 
 
-- (o)??
 
select stu_no , stu_name
from student s 
where not exists
 
(select *
from circle c
where c.stu_no = 20061011
and not EXISTS
 
(SELECT *
from circle c2
where c.cir_name = c2.cir_name
and s.stu_no = c2.stu_no)
);
 
 
 
 
-- 적어도 한 번 장학금을 받은 학생에 대하여 학번, 등록년도, 학기, 장학금액 중 가장 큰 장학금액, 등록일자를 출력하라 
-- 
-- (x)
select stu_no, fee_year, fee_term, jang_total, fee_date
from fee
group by stu_no
having jang_total = max(jang_total);
 
 
-- (o) ??
select stu_no, fee_year, fee_term, jang_total, fee_date
from fee f1
where jang_total=
(select max(jang_total)
from fee f2
where f1.stu_no = f2.stu_no);
 
 
 
 
 
-- 2007년 1학기에 등록한 학생이 같은 연도, 학기에 수강 신청한 학생의 학번과 등록년도, 등록학기,
-- 수강신청년도, 학기를 출력하라 (중복된 자료를 제거하기 위해서 distinct를 사용)
 
-- (x)
select DISTINCT f1.stu_no, f1.fee_year, f1.fee_term, a1.att_year, a1.att_term
from fee f1, attend a1
where f1.stu_no=a1.stu_no
and f1.fee_year = 2007
and f1.fee_term =1;
 
 
 
select DISTINCT f1.stu_no, f1.fee_year, f1.fee_term, a1.att_year, a1.att_term
from fee f1, attend a1
where f1.stu_no=a1.stu_no
and f1.fee_year = 2007
and f1.fee_term =1
and f1.fee_year = a1.att_year
and f1.fee_term = a1.att_term
;
 
cs


 


List of Articles
번호 제목 날짜 조회 수
126 mysql table 값 변경 mariadb 테이블 값 변경 2023.01.12 83
125 FORMAT 문법 사용 하기(숫자 자리수 나타내기) file 2023.01.10 98
124 MYSQL IN&BETWEEN&NULL&예제&FROM절 문제3 file 2021.03.27 104
123 MYSQL any&all&in&예제& WHERE 절 문제4 file 2021.03.27 111
122 CASE 문법 사용 하기 file 2023.01.10 111
121 데이터베이스별 / 테이블별 용량 확인 하기 2023.01.10 115
120 mysql-bin(binary log)파일 정리 및 삭제 2023.01.12 117
119 MYSQL Groupby & having 예제 문제 6 file 2021.03.27 118
118 no exists, not in 을 이용한 조건에 만족하지 않는 것들 구하기, 둘의 차이점 2021.03.26 125
117 fulltext 관련 글 2021.03.26 125
116 MYSQL order by 예제&문제 7 file 2021.03.27 126
115 column의 정보 중에서 column 설명(column_comment) 2021.03.26 129
114 binlog 조회 / 삭제 / 보관 기간 설정 file 2023.01.10 129
113 MYSQL FULLTEXT INDEX & PARTION 검색기능향상&파티션 file 2021.03.27 131
» MYSQL 부속질의어 예제&문제 9 file 2021.03.27 134
111 MYSQL 기초문법&예제&문제 2 file 2021.03.27 136
110 MYSQL 통계 함수 SUM AVG MAX MIN 예제 문제 5 file 2021.03.27 137
109 MYSQL select 명령문의 조합 &union 예제&문제 8 file 2021.03.27 138
108 MariaDB can't create test file lower-test 2023.02.16 139
107 엑셀로 되어있는 부분 db로 import하는 방법 2020.07.28 144
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved