메뉴 건너뛰기

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


  1. MYSQL Groupby & having 예제 문제 6

    Date2021.03.27 Views118
    Read More
  2. MYSQL FULLTEXT INDEX & PARTION 검색기능향상&파티션

    Date2021.03.27 Views131
    Read More
  3. MySQL DB 에 한글 utf8 문자열 INSERT 오류 해결 방법

    Date2018.07.18 Views2039
    Read More
  4. MYSQL any&all&in&예제& WHERE 절 문제4

    Date2021.03.27 Views111
    Read More
  5. MyISAM 스토리지 엔진에서 테이블의 최대 저장 row 개수

    Date2018.07.18 Views1558
    Read More
  6. mariaDB 백업 쉘 스크립트

    Date2019.03.05 Views1219
    Read More
  7. MariaDB can't create test file lower-test

    Date2023.02.16 Views139
    Read More
  8. LIMIT 속도 저하

    Date2021.03.26 Views247
    Read More
  9. InnoDB, MyISAM

    Date2016.12.23 Views5536
    Read More
  10. InnoDB 스토리지 엔진에서 테이블의 최대 저장 row 개수

    Date2018.07.18 Views1675
    Read More
  11. IN 연산자

    Date2016.12.23 Views5809
    Read More
  12. IMPORT

    Date2016.12.23 Views5440
    Read More
  13. group by로 뽑아온 값중에 가장큰 값(max)의 상태값을 가져오기

    Date2021.03.26 Views594
    Read More
  14. group by, distinct, count 를 이용한 겹치지 않는것의 개수

    Date2021.03.26 Views262
    Read More
  15. fulltext 관련 글

    Date2021.03.26 Views125
    Read More
  16. FORMAT 문법 사용 하기(숫자 자리수 나타내기)

    Date2023.01.10 Views102
    Read More
  17. flush privileges 명령어

    Date2017.04.12 Views5303
    Read More
  18. dump 를 db에 올릴때 인코딩 문제

    Date2016.12.23 Views5871
    Read More
  19. Dump & Restore

    Date2016.12.23 Views5788
    Read More
  20. DISTINCT와 ALL

    Date2016.12.23 Views5498
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved