메뉴 건너뛰기

조회 수 116 추천 수 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
번호 제목 날짜 조회 수
106 LIMIT 속도 저하 2021.03.26 263
105 fulltext 관련 글 2021.03.26 134
104 order by field 와 union, 원하는 대로 정렬 하기 2021.03.26 780
103 테이블, 컬럼 charset 변경 2021.03.26 192
102 no exists, not in 을 이용한 조건에 만족하지 않는 것들 구하기, 둘의 차이점 2021.03.26 133
101 group by로 뽑아온 값중에 가장큰 값(max)의 상태값을 가져오기 2021.03.26 604
100 group by, distinct, count 를 이용한 겹치지 않는것의 개수 2021.03.26 273
99 mysqlbinlog (mysql 백업, 로그남기기) 2021.03.26 212
98 mysql 포트 바꾸기, 외부에서 접속하기 2021.03.26 5108
97 테이블, 레코드 복사 2021.03.26 175
96 BEGIN, COMMIT, ROLLBACK 2021.03.26 326
95 column의 정보 중에서 column 설명(column_comment) 2021.03.26 140
94 [mysql,mariaDB] 컬럼 암호화, 복호화 2020.11.25 790
93 MySQL 암호화 방법 2020.11.25 372
92 일반적인 오류를 해결하는 유용한 정보들 file 2020.11.23 3906
91 서로 다른 결과를 한줄로 합쳐서 보여줘야 할 때(GROUP_CONCAT) file 2020.07.28 753
90 엑셀로 되어있는 부분 db로 import하는 방법 2020.07.28 155
89 하나의 쿼리로 여러 테이블의 데이터 삭제 file 2020.07.28 901
88 UPDATE ~ CASE 문을 사용한 조건별 업데이트 file 2020.07.28 1413
87 이벤트 스케줄러 등록하기 file 2020.06.29 319
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved