메뉴 건너뛰기

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

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

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

 

-- 수강신청을 한 학생의 학번과 이름을 출력하라

 

select DISTINCT s.stu_no,s.stu_name

from attend a, student s

where a.stu_no= s.stu_no;

 

 

select stu_no, stu_name

from student

where stu_no in 

(select stu_no from attend where att_div='Y');

 

 

-- 김유미 (1983)보다 나이가 더 많은 각 학생의 학번과 이름 주민번호를 출력하라

 

 

select stu_no, stu_name, id_num

from student

where birth_year <

(SELECT birth_year FROM STUDENT where stu_name='김유미');

 

 

 

 

-- 가장 나이가 많은 학생의 학번, 이름, 출생년도를 출력하라 

 

select stu_no, stu_name, birth_year

from student

where birth_year = (select min(birth_year) from student );

 

 

select stu_no, stu_name, birth_year

from student

where birth_year <= all (select birth_year from student);

 

 

-- 가장나이가 많은 학생을 제외한 나머지 모든 학생의 학번, 이름, 주민번호를 출력하라

 

 

 

select stu_no, stu_name, birth_year

from student

where birth_year != (select min(birth_year) from student );

 

 

 

select stu_no, stu_name, birth_year

from student

where birth_year > any (select birth_year from student);

 

 

-- 학번이 20001015인 학생이 등록한 등록금의 납부총액보다 더 많은 등록금을 낸 학생의 학번을 출력하라

-- 이때 20001015번은 제외한다.

 

select DISTINCT stu_no 

from fee

where fee_pay >

(select max(fee_pay) from fee where stu_no=20001015

);

 

 

 

select DISTINCT stu_no 

from fee

where stu_no <> '20001015'

and fee_pay > 

any (select fee_pay from fee where stu_no = '20001015')

;

 

 

 

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

 

select stu_no, stu_name

from student

where stu_no in 

(select stu_no from fee);

 

 

 

select stu_no, stu_name

from student

WHERE EXISTS

(select * from fee where stu_no = student.stu_no);

 

 

-- 등록하지 않은 학생의 학번과 이름을 출력하라

select stu_no, stu_name

from student

WHERE not EXISTS

(select * from fee where stu_no = student.stu_no);

 

 

 

 

 

-- 각각의 도시에 거주하는 모든 학생에 대하여 휴대폰을 가지고 있는 학생의 학번과 이름

-- 우편번호 , 휴대폰 번호를 나타내어라 (단, 휴대폰이 있는 학생과 휴대폰이 없는 학생의 우편번호 앞 

-- 3자리가 동일한 학생은 제외 시킨다. )

 

 

 

select stu_no,stu_name, post_no,phone_no 

from student 

where phone_no is not null

and substring(post_no,1,3) not in

(select  substring(post_no,1,3) from  student where phone_no is null);

 

 

-- java길라잡이 동아리에 가입한 학생의 학번과 이름을 출력하라

 

select stu_no from circle where cir_name='java길라잡이';

 

-- java길라잡이 동아리에 가입하지 않은 학생의 학번과 이름을 출력하라

 

 

select stu_no from circle where cir_name <>'java길라잡이';

 

 

-- 등록테이블에서 장학코드가 11 학생의 학번과 장학코드 장학금 총액을 출력하라

 

select stu_no, jang_total from fee where jang_code='11';

 

-- 등록테이블에서 장학코드가 11이 아닌 학생의 학번과 장학코드 장학금 총액을 출력하라 

 

select stu_no, jang_total from fee where jang_code <>'11';

 

 

-- 등록테이블에서 장학코드가 11이 아닌 학생의 학번과 장학코드 장학금 총액을 출력하라 (not in 이용)

 

select stu_no, jang_total

from fee

where jang_code 

not in(

select jang_code 

from fee where jang_code='11');

 

 

 

-- 등록테이블에서 장학코드가 11이 아닌 학생의 학번과 장학코드 장학금총액을 출력하라 

-- 단, not in을 이용하고 장학코드가 null인 학생도 포함하여 출력하라

 

 

select stu_no, jang_total

from fee

where jang_code 

not in(

select jang_code 

from fee where jang_code='11')

or jang_code is null;

 

 

 

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
 
-- 수강신청을 한 학생의 학번과 이름을 출력하라
 
select DISTINCT s.stu_no,s.stu_name
from attend a, student s
where a.stu_no= s.stu_no;
 
 
select stu_no, stu_name
from student
where stu_no in 
(select stu_no from attend where att_div='Y');
 
 
-- 김유미 (1983)보다 나이가 더 많은 각 학생의 학번과 이름 주민번호를 출력하라
 
 
select stu_no, stu_name, id_num
from student
where birth_year <
(SELECT birth_year FROM STUDENT where stu_name='김유미');
 
 
 
 
-- 가장 나이가 많은 학생의 학번, 이름, 출생년도를 출력하라 
 
select stu_no, stu_name, birth_year
from student
where birth_year = (select min(birth_year) from student );
 
 
select stu_no, stu_name, birth_year
from student
where birth_year <= all (select birth_year from student);
 
 
-- 가장나이가 많은 학생을 제외한 나머지 모든 학생의 학번, 이름, 주민번호를 출력하라
 
 
 
select stu_no, stu_name, birth_year
from student
where birth_year != (select min(birth_year) from student );
 
 
 
select stu_no, stu_name, birth_year
from student
where birth_year > any (select birth_year from student);
 
 
-- 학번이 20001015인 학생이 등록한 등록금의 납부총액보다 더 많은 등록금을 낸 학생의 학번을 출력하라
-- 이때 20001015번은 제외한다.
 
select DISTINCT stu_no 
from fee
where fee_pay >
(select max(fee_pay) from fee where stu_no=20001015
);
 
 
 
select DISTINCT stu_no 
from fee
where stu_no <> '20001015'
and fee_pay > 
any (select fee_pay from fee where stu_no = '20001015')
;
 
 
 
-- 등록을 한 학생의 학번과 이름을 출력하라
 
select stu_no, stu_name
from student
where stu_no in 
(select stu_no from fee);
 
 
 
select stu_no, stu_name
from student
WHERE EXISTS
(select * from fee where stu_no = student.stu_no);
 
 
-- 등록하지 않은 학생의 학번과 이름을 출력하라
select stu_no, stu_name
from student
WHERE not EXISTS
(select * from fee where stu_no = student.stu_no);
 
 
 
 
 
-- 각각의 도시에 거주하는 모든 학생에 대하여 휴대폰을 가지고 있는 학생의 학번과 이름
-- 우편번호 , 휴대폰 번호를 나타내어라 (단, 휴대폰이 있는 학생과 휴대폰이 없는 학생의 우편번호 앞 
-- 3자리가 동일한 학생은 제외 시킨다. )
 
 
 
select stu_no,stu_name, post_no,phone_no 
from student 
where phone_no is not null
and substring(post_no,1,3not in
(select  substring(post_no,1,3from  student where phone_no is null);
 
 
-- java길라잡이 동아리에 가입한 학생의 학번과 이름을 출력하라
 
select stu_no from circle where cir_name='java길라잡이';
 
-- java길라잡이 동아리에 가입하지 않은 학생의 학번과 이름을 출력하라
 
 
select stu_no from circle where cir_name <>'java길라잡이';
 
 
-- 등록테이블에서 장학코드가 11 학생의 학번과 장학코드 장학금 총액을 출력하라
 
select stu_no, jang_total from fee where jang_code='11';
 
-- 등록테이블에서 장학코드가 11이 아닌 학생의 학번과 장학코드 장학금 총액을 출력하라 
 
select stu_no, jang_total from fee where jang_code <>'11';
 
 
-- 등록테이블에서 장학코드가 11이 아닌 학생의 학번과 장학코드 장학금 총액을 출력하라 (not in 이용)
 
select stu_no, jang_total
from fee
where jang_code 
not in(
select jang_code 
from fee where jang_code='11');
 
 
 
-- 등록테이블에서 장학코드가 11이 아닌 학생의 학번과 장학코드 장학금총액을 출력하라 
-- 단, not in을 이용하고 장학코드가 null인 학생도 포함하여 출력하라
 
 
select stu_no, jang_total
from fee
where jang_code 
not in(
select jang_code 
from fee where jang_code='11')
or jang_code is null;
 
cs



출처: https://abc1211.tistory.com/116?category=925981 [길위의 개발자]


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

© k2s0o1d4e0s2i1g5n. All Rights Reserved