Connected to Oracle Database 11g Release 11.2.0.1.0
Connected as hr@ORCL
SQL> select avg(salary),sum(salary) from employees;
AVG(SALARY) SUM(SALARY)
6461.831775 691416
SQL> select min(salary) ,max(salary) from employees;
MIN(SALARY) MAX(SALARY)
2100 24000
SQL> select count() from employees;
COUNT()
107
SQL> select count(commission_pct) from employees e where e.department_id=80;
COUNT(COMMISSION_PCT)
34
SQL> select count(distinct department_id) from employees;
SQL> select count(distinct department_id) from employees;
COUNT(DISTINCTDEPARTMENT_ID)
11
SQL> select avg(commission_pct) from employees;
AVG(COMMISSION_PCT)
0.222857142857143
SQL> select avg(nvl(commission_pct,0)) from employees;
AVG(NVL(COMMISSION_PCT,0))
0.0728971962616822
SQL> select departments_id,avg(salary) from employees e group by e.department_id;
select departments_id,avg(salary) from employees e group by e.department_id
ORA-00904: “DEPARTMENTS_ID”: 标识符无效
SQL> select department_id,avg(salary) from employees e group by e.department_id;
DEPARTMENT_ID AVG(SALARY)
100 8601.333333
30 4150
7000
90 19333.33333
20 9500
70 10000
110 10154
50 3475.555555
80 8955.882352
40 6500
60 5760
10 4400
12 rows selected
SQL> select department_id,job_id,sum(salary) from employees group by department_id,job_id order by department_id;
DEPARTMENT_ID JOB_ID SUM(SALARY)
10 AD_ASST 4400
20 MK_MAN 13000
20 MK_REP 6000
30 PU_CLERK 13900
30 PU_MAN 11000
40 HR_REP 6500
50 SH_CLERK 64300
50 ST_CLERK 55700
50 ST_MAN 36400
60 IT_PROG 28800
70 PR_REP 10000
80 SA_MAN 61000
80 SA_REP 243500
90 AD_PRES 24000
90 AD_VP 34000
100 FI_ACCOUNT 39600
100 FI_MGR 12008
110 AC_ACCOUNT 8300
110 AC_MGR 12008
SA_REP 7000
20 rows selected
SQL> select department_id,max(salary) from emplyees group by department_id having max(salary)>10000;
select department_id,max(salary) from emplyees group by department_id having max(salary)>10000
ORA-00942: 表或视图不存在
SQL> select department_id,max(salary) from employees group by department_id having max(salary)>10000;
DEPARTMENT_ID MAX(SALARY)
100 12008
30 11000
90 24000
20 13000
110 12008
80 14000
6 rows selected
SQL> select e.department_id,avg(e.salary) from employees e group by e.department_id having max(e.salary)>10000;
DEPARTMENT_ID AVG(E.SALARY)
100 8601.33333333
30 4150
90 19333.3333333
20 9500
110 10154
80 8955.88235294
6 rows selected
SQL> select e.department_id, max(avg(e.salary)) from employees e group by e.department_id;
select e.department_id, max(avg(e.salary)) from employees e group by e.department_id
ORA-00937: 不是单组分组函数
SQL> select e.department_id, max(avg(e.salary)) from employees e group by e.department_id;
select e.department_id, max(avg(e.salary)) from employees e group by e.department_id
ORA-00937: 不是单组分组函数
SQL> select max(avg(e.salary)) from employees e group by e.department_id;
MAX(AVG(E.SALARY))
19333.3333333333
SQL> select max(avg(e.salary)) from employees e group by e.job_id;
SQL> select max(avg(e.salary)) from employees e group by e.job_id;
MAX(AVG(E.SALARY))
24000
SQL> select last_name,max(salary) from employees group by last_name;
LAST_NAME MAX(SALARY)
Greenberg 12008
Markle 2200
Marlow 2500
Gee 2400
Philtanker 2200
Stiles 3200
Rajs 3500
Bates 7300
Dellinger 3400
Perkins 2500
Mavris 6500
Weiss 8000
Mallin 3300
Errazuriz 12000
Hall 9000
Tuvault 7000
Bloom 10000
Johnson 6200
Fleaur 3100
Sullivan 2500
LAST_NAME MAX(SALARY)
Geoni 2800
Bull 4100
Cabrio 3000
Dilly 3600
OConnell 2600
Fay 6000
Chen 8200
Raphaely 11000
Nayer 3200
Mikkilineni 2700
Davies 3100
Grant 7000
Austin 4800
Pataballa 4800
Lorentz 4200
Popp 6900
Ladwig 3600
Matos 2600
Partners 13500
Bernstein 9500
Vishney 10500
LAST_NAME MAX(SALARY)
Greene 9500
Banda 6200
Hutton 8800
Baer 10000
Gietz 8300
Kochhar 17000
De Haan 17000
Hunold 9000
Sciarra 7700
Khoo 3100
Kaufling 7900
Vollman 6500
Landry 2400
Tucker 10000
McEwen 9000
Doran 7500
Taylor 8600
Livingston 8400
Gates 2900
Whalen 4400
King 24000
LAST_NAME MAX(SALARY)
Ernst 6000
Urman 7800
Tobias 2800
Fripp 8200
Bissot 3300
Olson 2100
Rogers 2900
Patel 2500
Russell 14000
Lee 6800
Ande 6400
Bell 4000
McCain 3200
Hartstein 13000
Baida 2900
Himuro 2600
Colmenares 2500
Atkinson 2800
Zlotkey 10500
Olsen 8000
Sully 9500
LAST_NAME MAX(SALARY)
Marvins 7200
Ozer 11500
Kumar 6100
Abel 11000
Sarchand 4200
Everett 3900
Jones 2800
Walsh 3100
Feeney 3000
Faviet 9000
Mourgos 5800
Seo 2700
Vargas 2500
Cambrault 11000
Smith 8000
Sewall 7000
Fox 9600
Chung 3800
Higgins 12008
102 rows selected
SQL> select max(salary),min(salary),sum(salary),avg(salary) from employees;
MAX(SALARY) MIN(SALARY) SUM(SALARY) AVG(SALARY)
24000 2100 691416 6461.831775
SQL> select max(salary),min(salary),sum(salary),avg(salary) from employees group by job_id;;
select max(salary),min(salary),sum(salary),avg(salary) from employees group by job_id;
ORA-00911: 无效字符
SQL> select max(salary),min(salary),sum(salary),avg(salary) from employees group by job_id;
MAX(SALARY) MIN(SALARY) SUM(SALARY) AVG(SALARY)
9000 4200 28800 5760
12008 12008 12008 12008
8300 8300 8300 8300
8200 5800 36400 7280
11000 11000 11000 11000
4400 4400 4400 4400
17000 17000 34000 17000
4200 2500 64300 3215
9000 6900 39600 7920
12008 12008 12008 12008
3100 2500 13900 2780
14000 10500 61000 12200
13000 13000 13000 13000
10000 10000 10000 10000
24000 24000 24000 24000
11500 6100 250500 8350
6000 6000 6000 6000
3600 2100 55700 2785
6500 6500 6500 6500
19 rows selected
SQL> select job_id,count() from employees group by job_id;
JOB_ID COUNT()
AC_ACCOUNT 1
AC_MGR 1
AD_ASST 1
AD_PRES 1
AD_VP 2
FI_ACCOUNT 5
FI_MGR 1
HR_REP 1
IT_PROG 5
MK_MAN 1
MK_REP 1
PR_REP 1
PU_CLERK 5
PU_MAN 1
SA_MAN 5
SA_REP 30
SH_CLERK 20
ST_CLERK 20
ST_MAN 5
19 rows selected
SQL> select count(distinct manager_id) from employees;
COUNT(DISTINCTMANAGER_ID)
18
SQL> select em.last_name,em.salary from employees abel,employees em where abel.last_name=‘Abel’ and em.salary>abel.salary;
LAST_NAME SALARY
King 24000.00
Kochhar 17000.00
De Haan 17000.00
Greenberg 12008.00
Russell 14000.00
Partners 13500.00
Errazuriz 12000.00
Ozer 11500.00
Hartstein 13000.00
Higgins 12008.00
10 rows selected
SQL> select m.salary from employees m where m.last_name=‘Abel’;
SALARY
11000.00
SQL> select em.last_name,em.salary from employees em where em.salary>(select m.salary from employees m where m.last_name=‘Abel’);
LAST_NAME SALARY
King 24000.00
Kochhar 17000.00
De Haan 17000.00
Greenberg 12008.00
Russell 14000.00
Partners 13500.00
Errazuriz 12000.00
Ozer 11500.00
Hartstein 13000.00
Higgins 12008.00
10 rows selected
SQL> select job_id from employees e where e.employee_id=141;
JOB_ID
ST_CLERK
SQL> select em.last_name,em.job_id from employees em where em.job_id=(select job_id from employees e where e.employee_id=141);
LAST_NAME JOB_ID
Nayer ST_CLERK
Mikkilineni ST_CLERK
Landry ST_CLERK
Markle ST_CLERK
Bissot ST_CLERK
Atkinson ST_CLERK
Marlow ST_CLERK
Olson ST_CLERK
Mallin ST_CLERK
Rogers ST_CLERK
Gee ST_CLERK
Philtanker ST_CLERK
Ladwig ST_CLERK
Stiles ST_CLERK
Seo ST_CLERK
Patel ST_CLERK
Rajs ST_CLERK
Davies ST_CLERK
Matos ST_CLERK
Vargas ST_CLERK
20 rows selected
SQL> select from employees emp where emp.employee_id=143;
select from employees emp where emp.employee_id=143
ORA-00936: 缺失表达式
SQL> select emp.salary from employees emp where emp.employee_id=143;
SALARY
2600.00
SQL> select em.job_id from employees em where em.employee_id=141;
JOB_ID
ST_CLERK
SQL> select e.last_name,e.job_id,e.salary from employees e where e.job_id=(select em.job_id from employees em where em.employee_id=141)and e.salary>(select emp.salary from employees emp where emp.employee_id=143);
SQL> select e.last_name,e.job_id,e.salary from employees e where e.job_id=(select em.job_id from employees em where em.employee_id=141)and e.salary>(select emp.salary from employees emp where emp.employee_id=143);
LAST_NAME JOB_ID SALARY
Nayer ST_CLERK 3200.00
Mikkilineni ST_CLERK 2700.00
Bissot ST_CLERK 3300.00
Atkinson ST_CLERK 2800.00
Mallin ST_CLERK 3300.00
Rogers ST_CLERK 2900.00
Ladwig ST_CLERK 3600.00
Stiles ST_CLERK 3200.00
Seo ST_CLERK 2700.00
Rajs ST_CLERK 3500.00
Davies ST_CLERK 3100.00
11 rows selected
SQL> select min(salary) from employees;
MIN(SALARY)
2100
SQL> select em.last_name,em.job_id,em.salary from employees em where em.salary=(select min(salary) from employees);
LAST_NAME JOB_ID SALARY
Olson ST_CLERK 2100.00
SQL> select min(e.salary) from employees e where e.department_id=50;
MIN(E.SALARY)
2100
SQL> select em.department_id,min(em.salary) from employees em group by em.department_id having min(em.salary)>(select min(e.salary) from employees e where e.department_id=50);
DEPARTMENT_ID MIN(EM.SALARY)
100 6900
30 2500
7000
90 17000
20 6000
70 10000
110 8300
80 6100
40 6500
60 4200
10 4400
11 rows selected
SQL> select min(em.salary) from employees em group by em.department_id;
SQL> select min(em.salary) from employees em group by em.department_id;
MIN(EM.SALARY)
6900
2500
7000
17000
6000
10000
8300
2100
6100
6500
4200
4400
12 rows selected
SQL> select e.last_name,e.department_id,e.salary from employees e where e.salary in(select min(em.salary) from employees em group by em.department_id);
LAST_NAME DEPARTMENT_ID SALARY
Kochhar 90 17000.00
De Haan 90 17000.00
Ernst 60 6000.00
Lorentz 60 4200.00
Popp 100 6900.00
Colmenares 30 2500.00
Vollman 50 6500.00
Marlow 50 2500.00
Olson 50 2100.00
Patel 50 2500.00
Vargas 50 2500.00
Tucker 80 10000.00
Tuvault 80 7000.00
King 80 10000.00
Sewall 80 7000.00
Bloom 80 10000.00
Kumar 80 6100.00
Grant 7000.00
Sullivan 50 2500.00
Sarchand 50 4200.00
LAST_NAME DEPARTMENT_ID SALARY
Perkins 50 2500.00
Whalen 10 4400.00
Fay 20 6000.00
Mavris 40 6500.00
Baer 70 10000.00
Gietz 110 8300.00
26 rows selected
SQL> select max(salary) from employees;
MAX(SALARY)
24000
SQL> select last_name from employees where salary=(select max(salary) from employees);
LAST_NAME
King
SQL> select em.salary from employees em where em.job_id=‘IT_PROG’ ;
SALARY
9000.00
6000.00
4800.00
4800.00
4200.00
SQL> select e.employee_id,e.last_name,e.job_id,e.salary from employees e where e.job_id<>‘IT_PROG’ and e.salary< any(select em.salary from employees em where em.job_id=‘IT_PROG’);
EMPLOYEE_ID LAST_NAME JOB_ID SALARY
132 Olson ST_CLERK 2100.00
136 Philtanker ST_CLERK 2200.00
128 Markle ST_CLERK 2200.00
135 Gee ST_CLERK 2400.00
127 Landry ST_CLERK 2400.00
191 Perkins SH_CLERK 2500.00
182 Sullivan SH_CLERK 2500.00
144 Vargas ST_CLERK 2500.00
140 Patel ST_CLERK 2500.00
131 Marlow ST_CLERK 2500.00
119 Colmenares PU_CLERK 2500.00
118 Himuro PU_CLERK 2600.00
198 OConnell SH_CLERK 2600.00
199 Grant SH_CLERK 2600.00
143 Matos ST_CLERK 2600.00
126 Mikkilineni ST_CLERK 2700.00
139 Seo ST_CLERK 2700.00
117 Tobias PU_CLERK 2800.00
183 Geoni SH_CLERK 2800.00
130 Atkinson ST_CLERK 2800.00
EMPLOYEE_ID LAST_NAME JOB_ID SALARY
195 Jones SH_CLERK 2800.00
190 Gates SH_CLERK 2900.00
116 Baida PU_CLERK 2900.00
134 Rogers ST_CLERK 2900.00
197 Feeney SH_CLERK 3000.00
187 Cabrio SH_CLERK 3000.00
115 Khoo PU_CLERK 3100.00
196 Walsh SH_CLERK 3100.00
142 Davies ST_CLERK 3100.00
181 Fleaur SH_CLERK 3100.00
194 McCain SH_CLERK 3200.00
138 Stiles ST_CLERK 3200.00
125 Nayer ST_CLERK 3200.00
180 Taylor SH_CLERK 3200.00
129 Bissot ST_CLERK 3300.00
133 Mallin ST_CLERK 3300.00
186 Dellinger SH_CLERK 3400.00
141 Rajs ST_CLERK 3500.00
137 Ladwig ST_CLERK 3600.00
189 Dilly SH_CLERK 3600.00
188 Chung SH_CLERK 3800.00
EMPLOYEE_ID LAST_NAME JOB_ID SALARY
193 Everett SH_CLERK 3900.00
192 Bell SH_CLERK 4000.00
185 Bull SH_CLERK 4100.00
184 Sarchand SH_CLERK 4200.00
200 Whalen AD_ASST 4400.00
124 Mourgos ST_MAN 5800.00
202 Fay MK_REP 6000.00
173 Kumar SA_REP 6100.00
179 Johnson SA_REP 6200.00
167 Banda SA_REP 6200.00
166 Ande SA_REP 6400.00
123 Vollman ST_MAN 6500.00
203 Mavris HR_REP 6500.00
165 Lee SA_REP 6800.00
113 Popp FI_ACCOUNT 6900.00
161 Sewall SA_REP 7000.00
178 Grant SA_REP 7000.00
155 Tuvault SA_REP 7000.00
164 Marvins SA_REP 7200.00
172 Bates SA_REP 7300.00
171 Smith SA_REP 7400.00
EMPLOYEE_ID LAST_NAME JOB_ID SALARY
154 Cambrault SA_REP 7500.00
160 Doran SA_REP 7500.00
111 Sciarra FI_ACCOUNT 7700.00
112 Urman FI_ACCOUNT 7800.00
122 Kaufling ST_MAN 7900.00
153 Olsen SA_REP 8000.00
159 Smith SA_REP 8000.00
120 Weiss ST_MAN 8000.00
121 Fripp ST_MAN 8200.00
110 Chen FI_ACCOUNT 8200.00
206 Gietz AC_ACCOUNT 8300.00
177 Livingston SA_REP 8400.00
176 Taylor SA_REP 8600.00
175 Hutton SA_REP 8800.00
76 rows selected
SQL> creat table dept(deptno number(2),dname varchar2(14),loc varchar2(13));
SQL>creat table dept(deptno number(2),dname varchar2(14),loc varchar2(13));
reat table dept(deptno number(2),dname varchar2(14),loc varchar2(13))
ORA-00900: 无效 SQL 语句
SQL> creat table dept(deptno number(2),dname varchar2(14),loc varchar2(13));
creat table dept(deptno number(2),dname varchar2(14),loc varchar2(13))
ORA-00900: 无效 SQL 语句
SQL> create table dept(deptno number(2),dname varchar2(14),loc varchar2(13));
Table created
SQL> select table_name from user_name;
select table_name from user_name
ORA-00942: 表或视图不存在
SQL> create table dept80 as select employee_id,last_name name,salary,hire_date from employees e where e.department_id=80;
Table created
SQL> alter dept add(salary number(8,2));
alter dept add(salary number(8,2))
ORA-00940: 无效的 ALTER 命令
SQL> create table dept80(id number,name varchar2(20) not null,salary number constraint dept80_notn not null);
create table dept80(id number,name varchar2(20) not null,salary number constraint dept80_notn not null)
ORA-00955: 名称已由现有对象使用
SQL> create table dept81(id number,name varchar2(20) not null,salary number constraint dept80_notn not null);
Table created
SQL> alter table dept81 modify location_id not null;
alter table dept81 modify location_id not null
ORA-00904: “LOCATION_ID”: 标识符无效
SQL> alter table dept81 modify location_id not null;
alter table dept81 modify location_id not null
ORA-00904: “LOCATION_ID”: 标识符无效
SQL> create table aa(department_id number(4),department_name varchar2(30) constraint dept_name_nn not null,manager_id number(6),location_id number(4),constraint dept_id_pk primary key(department id));
create table aa(department_id number(4),department_name varchar2(30) constraint dept_name_nn not null,manager_id number(6),location_id number(4),constraint dept_id_pk primary key(department id))
ORA-00907: 缺失右括号
SQL>