메뉴 건너뛰기

조회 수 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 [길위의 개발자]


List of Articles
번호 제목 날짜 조회 수
126 MySQL 최적화 방법 설명 2014.02.27 8022
125 MySql 문자열 합치기 2014.02.27 6254
124 컬럼내 특정 문자를 다른문자로 변경하고자 할때 2014.02.27 6012
123 MySQL Replication 설정(Master-Slave, Maste 2014.02.27 6782
122 Mysql 기본 명령어 2014.02.27 5693
121 MySQL/MariaDB 백업 & 복원 - mysqldump 2015.08.07 7384
120 다양한 단위의 시간차 구하기 2015.12.19 8360
119 월의 마지막 일수를 반환하는 함수입니다 2015.12.19 5996
118 DB의 모든 테이블을 삭제하는 쿼리 2016.08.29 6767
117 각각의 게시판에서 제일 최근글하나씩을 모아 정렬 2016.08.30 5812
116 컬럼에 포함된 특정문자열을 검색해서 그 문자로 또 다른 테이블검색하기 2016.08.30 6606
115 MySQL 서버 데몬이 죽었을때 다시 실행하는 방법 2016.08.30 5842
114 MySql 에서 외래키(FK) 설정하는 방법과 Toad 에서 확인하기 file 2016.08.30 7151
113 MySql 윈도우에서 DB dump 백업과 복구하기 file 2016.08.30 8475
112 MySQL 에서 NULL 값 처리 file 2016.08.30 6423
111 MySql 의 Trigger(트리거) 로 정보 업데이트 file 2016.08.30 10153
110 MySQL INSERT 성능 향상 2016.12.22 11523
109 mysql 날짜 관련 date_add, date_format 2016.12.23 5500
108 DISTINCT와 ALL 2016.12.23 5498
107 InnoDB, MyISAM 2016.12.23 5536
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved