Oracle数据库简单使用总结

查询员工在1982-1-1年之后入职的人

Like模糊查询

第三个字母为O的员工姓名

需要用到多个or的时候用“in()”代替

使用is null查询没有上级的雇员的情况

Select * from emp where (sal>500 or jop=’manager’ ) and ename like ‘J%’;

使用order by 实现降序desc排序 默认升序(asc)

按照部门升序 和 薪水降序

使用别名进行排序

工资高于平均工资的员工信息

Group by 分组函数; 查询每个部门的最高工资和平均工资

Select avg(sal), max(sal), deptno from emp group by deptno having avg(sal)>2000;

Select a1.dname, a2.ename,a2.sal from dept a1, emp a2 where a1.deptno =a2.deptno and a1.deptno = 10;

Between使用

Select a1.ename ,a1.sal,a2.grade from emp a1,salgrade a2 where a1.sal between a2.losal and a2.hisal;

Select a1.ename,a1.sal,a2.dname,a2.deptno from emp a1,dept a2 where a1.deptno=a2.deptno order by a2.deptno;

自链接

select w.ename,b.ename from emp w, emp b where w.mgr=b.empno and w.ename='FORD';

多行子查询

select * from emp where job in (select distinct job from emp where deptno=10);

distinct 去除重复行

多列子查询

select * from emp where (deptno, job)=(select deptno, job from emp where ename='SMITH');

方法1

select * from emp a1, (select avg(sal) mysal,deptno from emp group by deptno)a2 where a1.deptno = a2.deptno and a1.sal>a2.mysal;

方法2

select * from emp , dept where emp.deptno=dept.deptno and emp.sal>(select avg(sa) deptno from emp group by deptno);

rownum 分页查询 当公式用来记忆

select * from (select a1.* ,rownum rn from (select * from emp) a1 where rownum<=10) where rn>5;

用查询结果创建表

合并查询

union

Union all

intersect

minus

添加

Insert into 表名(列名1,列名2) values (值1,值2);

修改

Update 表名 sel 字段1=值1,字段2=值2 where 条件;

删除

Delete from 表名 where 条件;

posted @ 2021-01-22 08:23  My--style  阅读(45)  评论(0)    收藏  举报