-
Notifications
You must be signed in to change notification settings - Fork 0
/
숙제.sql
240 lines (176 loc) · 4.92 KB
/
숙제.sql
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
SELECT *
FROM departments;
SELECT *
FROM 부서명;
/*한글도 먹는다*/
SELECT *
FROM employees;
/*사원*/
SELECT department_id, location_id
From departments;
SELECT location_id, department_id
From departments;
/*셀렉트절 나열 순서대로 결과가 이뤄짐*/
SELECT department_id, department_id
From departments;
/*같은 거를 두번 나열해도 ㄱㄴ*/
SELECT last_name
From employees;
SELECT last_name,salary
From employees;
/*숫자는 왼쪽정렬 > 대문자*/
/*산술 연산자 ㄱㄴ*/
SELECT last_name, salary, salary+300
FROM employees;
SELECT last_name, salary, 12*salary+100
FROM employees;
SELECT last_name, salary, 12+(salary+100)
FROM employees;
/*괄호 넣어주면 계산결과 다름*/
SELECT last_name, job_id, salary, commission_pct
FROM employees;
/*sql plus는 null이 안 나오고 공백으로 나옴*/
SELECT last_name, 12*salary*commission_pct
FROM employees;
/*커미션 안 받는 사람도 null*/
/*null인 경우 1로 바꿔주겠다 NVL 함수 꼭 붙이기...*/
SELECT last_name, 12*salary*NVL(commission_pct,1)
FROM employees;
/*column alias*/
SELECT last_name AS name, commission_pct comm
FROM employees;
/*큰따옴표 안은 대소문자 그대로~*/
SELECT last_name "Name", salary*12 "Annual Salary"
FROM employees;
/*한글 먹는다 그래도 가급적 영어로 사용!*/
SELECT last_name AS 이름, commission_pct 보너스
FROM employees;
/*연결 연산자*/
SELECT last_name || job_id AS "Employees"
FROM employees;
/*리터럴 문자열 연결해서 쓰는 연산자*/
SELECT last_name || 'is a' || job_id
AS "Employee Details"
FROM employees;
SELECT department_id
FROm employees;
SELECT DISTINCT department_id
FROM employees;
/**SELECT (ALL)DISTINCT department_id, job_id <<<ALL은 생략 default값이라...*/
SELECT DISTINCT department_id, job_id
FROM employees;
/*1*/
SELECT *
FROM departments;
/*2*/
DESC employees;
SELECT employee_id,last_name, job_id , hire_date AS STARTDATE
From employees;
/*3*/
SELECT DISTINCT job_id
From employees;
/*4*/
SELECT employee_id "EMP", last_name"Employee", job_id "job", hire_date " hire Date"
From employees;
/*5*/
SELECT job_id ||last_name AS "Employee and Title"
From employees;
/*emp로부터 90번 부서인 emp id, last name , job id ,d~말해라*/
SELECT employee_id, last_name, job_id, department_id
FROM employees
WHERE department_id = 90;
/*대소문자 구분*/
SELECT last_name, job_id, department_id
FROM employees
WHere last_name = 'Whalen';
SELECT last_name
FROM employees
WHERE hire_date ='05/10/10'
/*비교연산자*/
SELECT last_name,salary
FROM employees
WHERE salary <= 3000;
/*사원들 중 2005년 이전에 입사한 사원들의 사원이름,입사일 출력*/
SELECT last_name,hire_date
FROM employees
WHERE hire_date <'05/01/01' /*04/12/31*/
/*SQL 연산자*/
SELECT last_name, salary
FROM employees
WHERE salary BETWEEN 2500 AND 3500;
/*돌아는 가는데 결과가 안 나옴 여기서 결과가 나오면 쓰레기값!*/
SELECT last_name, salary
FROM employees
WHERE salary BETWEEN 3500 AND 2500;
/*IN = or*/
SELECT employee_id, last_name, salary, manager_id
FROM employees
WHERE manager_id IN (100,101,201);
/*LIKE = 대체문자*/
SELECT first_name
FROM employees
WHERE first_name LIKE 'S%';
/*사원들 중에서 사원이름(last name)의 끝글자에 소문자 's'가 들어가는 사원의 last_name*/
SELECT last_name
FROM employees
WHERE last_name LIKE '%s';
/*입사일 년도가 05년인 사람만 보겠다*/
SELECT last_name, hire_date
FROM employees
WHERE hire_date LIKE '05%'
/*입사일 날짜가 05인 사람만 보겠다*/
SELECT last_name, hire_date
FROM employees
WHERE hire_date LIKE '%05'
/*last 네임 두 번째 글자가 소문자 o인 사람*/
SELECT last_name, hire_date
FROM employees
WHERE last_name LIKE '_o%'
SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%SA_%';
/*모르겠음...*/
SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%SA\_%' ESCAPE '\';
SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%_%' ;
SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%\_M%';
SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%\_M%' ESCAPE '\' ;
/*WHERE commission_pct = null; 표준 x is가 표준임!*/
/*com~이 null인 사람만 보임*/
SELECT *
FROM employees
WHERE commission_pct is null;
/*우선순위는 and가 더높음*/
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary >= 10000
AND job_id LIKE '%MAN%';
/*or*/
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary >= 10000
OR job_id LIKE '%MAN%';
/*not*/
SELECT last_name, job_id
FROM employees
WHERE job_id
NOT IN ('IT_PROG', 'ST_CLERK','SA_REP');
SELECT last_name, job_id, salary
FROM employees
WHERE job_id = 'SA_REP' /*2*/
OR job_id = 'AD_PRES' /*1*/
AND salary > 15000;
/* job _id만 만족하면 되는 것*/
SELECT last_name, job_id, salary
FROM employees
WHERE (job_id = 'SA_REP'
OR job_id = 'AD_PRES')
AND salary > 15000;
/*시험*/