之前介绍了
接下来说一下DQL(data query language:数据库查询语言)操作,也就是详细介绍一下select
建议先执行下面的sql,创建基础表格,这个表格在oracle中是已经有的,当然执行下面sql创建也可以。
# 创建部门表
CREATE TABLE dept(
deptno int(2) not null,
dname varchar(14),# 部门名称
loc varchar(13)# 部门位置
)
# 添加部门表的主键约束
alter table dept add constraint pk_dept primary key (deptno);
# 创建员工表
create table emp(
empno int(4) primary key,# 员工编号
ename varchar(10),# 员工名字
job varchar(9),# 员工职位
mgr int(4),# 上级领导,内容是自身表的empno,但是没有关联
hiredate date,# 入职时间
sal double(7,2),# 工资
comm double(7,2),# 当月补助
deptno int(2)# 部门编号
);
# 员工表(子表)关联到部门表(主表)
alter table emp add constraint fk_deptno foreign key (deptno) references dept(deptno);
# 创建奖金等级表
create table salgrade(
grade int primary key,# 等级
losal double(7,2),# 最低工资
hisal double(7,2)# 最高工资
);
# 创建奖金表
create table bonus(
ename varchar(10), # 人名
job varchar(9),# 职位
sal double(7,2),# 薪水
comm double(7,2)# 奖金
);
# 插入数据
insert into dept(deptno,dname,loc) values(10,'accounting','new york'),(20,'research','dallas'),(30,'sales','chicago'),(40,'openations','boston');
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values
(7369,'smith','clerk',7902,'1980-12-17',800,null,20),
(7499,'allen','salesman',7698,'1981-02-20',1600,300,30),
(7521,'ward','salesman',7698,'1981-02-22',1250,500,30),
(7566,'jones','manager',7839,'1981-04-02',2975,null,20),
(7654,'martin','salesman',7698,'1981-09-28',1250,1400,30),
(7698,'blake','manager',7839,'1981-05-01',2850,null,30),
(7782,'clark','manager',7893,'1981-06-09',2450,null,10),
(7788,'scott','analyst',7566,'1987-04-19',3000,null,20),
(7839,'king','president',null,'1981-11-17',5000,null,10),
(7844,'turner','salesman',7698,'1981-09-08',1500,0,30),
(7879,'adams','clerk',7788,'1987-05-23',1100,null,20),
(7900,'james','clerk',7698,'1981-12-03',950,null,30),
(7902,'ford','analyst',7566,'1981-12-03',3000,null,20),
(7934,'miller','clerk',7782,'1982-01-23',1300,null,10);
insert into salgrade(grade,losal,hisal) values(1,700,1200),(2,1201,1400),(3,1401,2000),(4,2001,3000),(5,3001,9999);