메뉴 건너뛰기

조회 수 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 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
» 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
112 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