Oracle特有函数 case when decode exists 分页rownum
select * from EMP e
select * from dept d
select * from salgrade s
--Oracle特有函数 case when
select
case 2
when 1 then '一'
when 2 then '二'
when 3 then '三'
else '其他'
end
from dual;
--Oracle特有函数 decode
select decode(3,1,'一',2,'二',3,'三','其他')from dual;
--查询员工的领导信息(内联查询)
select e.empno,e.ename,e.job,e.mgr,'||',m.empno,m.ename,m.job
from emp e,emp m
where e.mgr=m.empno(+)
select *
from emp e right outer join emp m on e.mgr=m.empno;
select *
from emp e full outer join emp m on e.mgr=m.empno;
--查询员工的领导信息(内联查询)及员工部门名称
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,'||',m.empno,m.ename,m.job
from emp e,emp m,dept d
where e.mgr=m.empno and e.deptno=d.deptno
--查询员工的领导信息(内联查询)员工部门名称,领导部门名称
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,'||',m.empno,m.ename,m.job,p.dname
from emp e,emp m,dept d,dept p
where e.mgr=m.empno and e.deptno=d.deptno and m.deptno=p.deptno
--查询员工的领导信息(内联查询)员工部门名称,领导部门名称,员工工资等级,领导工资等级
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,s.grade,
'||',m.empno,m.ename,m.job,p.dname,s1.grade
from emp e,emp m,dept d,dept p,salgrade s,salgrade s1
where e.mgr=m.empno
and e.deptno=d.deptno
and m.deptno=p.deptno
and e.sal between s.losal and s.hisal
and m.sal between s1.losal and s1.hisal
--级别不用数字表示,用文字表示
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,
decode(s.grade,1,'一级',2,'二级',3,'三级',4,'四级',5,'五级','没级'),
'||',m.empno,m.ename,m.job,p.dname,
decode(s1.grade,1,'一级',2,'二级',3,'三级',4,'四级',5,'五级','没级')
from emp e,emp m,dept d,dept p,salgrade s,salgrade s1
where e.mgr=m.empno
and e.deptno=d.deptno
and m.deptno=p.deptno
and e.sal between s.losal and s.hisal
and m.sal between s1.losal and s1.hisal
--查询工资高于7369号员工工资的员工信息
select sal from emp where empno=7369
select * from emp where sal>(select sal from emp where empno=7369)
--查询存在员工的部门信息
select distinct deptno from emp
select * from dept where deptno in(select distinct deptno from emp )
select * from dept where deptno =any(select distinct deptno from emp )
select * from dept where deptno =some(select distinct deptno from emp )
--使用exists
select * from dept d where exists (select * from emp e where e.deptno=d.deptno)
--查询每个部门最低工资员工信息
select *
from emp e,(select min(sal) msal,deptno from emp group by deptno) t
where e.sal=t.msal
and e.deptno=t.deptno
--查询工资最高的前三名 (分页的感觉)
select * from
(select * from emp order by sal desc) t
where rownum <=3
Oracle特有函数 case when decode exists 分页rownum的更多相关文章
- Oracle数据库自带了decode()函数
Oracle数据库自带了decode()函数,函数的使用方法如下: SELECT emp.ename, emp.job, emp.sal, decode(job, 'manager ...
- Oracle trunc()函数,decode()函数,substr函数,GREATEST函数,java中substring函数的用法
--Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...
- Oracle初级函数的使用
--1.字符函数--UPPER(string|column) 可以将字符转成大写select upper('helloword') from dual;select upper(ename) from ...
- Oracle 转换函数
Oracle 转换函数 -- TO_CHAR(date|number {,fmt} {,nlsparams}) fmt:格式内容,返回的字符串是什么格式的,在此处指定:nlsparams:指定国家语言 ...
- SQL操作数据——SQL组成,查询基础语法,where,Oracle常用函数等
SQL组成 DML数据操作语言 DCL数据控制语言 DQL数据查询语言 DDL数据定义语言 查询基础语法 记录筛选 where 子句 记录筛选 where 子句 实例练习 实例练习 Select语句中 ...
- Oracle over函数
Oracle over函数 SQL code: sql over的作用及用法RANK ( ) OVER ( [query_partition_clause] order_by_clause )DE ...
- Oracle SQL函数
Oracle将函数大致分为单行函数,聚合函数和分析函数. 单行函数分为字符函数,日期函数,转换函数,数字函数,通用函数,decode函数 一.字符函数 1)大小写控制函数 01.Lower() 全部小 ...
- oracle,mysql,SqlServer三种数据库的分页查询的实例。
MySql: MySQL数据库实现分页比较简单,提供了 LIMIT函数.一般只需要直接写到sql语句后面就行了.LIMIT子 句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两个参数,如 ...
- oracle的函数
1:nvl函数 nvl函数将一个null值转换为一个实际的值,数据类型可以是日期,数字,字符,数据类型必须匹配,vl能够转换任何数据类型,但是转换的数据类型返回值必须是nvl(expr1,expr2) ...
随机推荐
- IE、火狐、谷歌浏览器下兼容统一select样式
项目开发时,对于不同浏览器下的select样式不统一问题,各种查,这里记录一下,项目已使用 IE浏览器下样式: 火狐浏览器下样式: 谷歌浏览器下样式: 上代码: 1.html 2.css 至此,大功告 ...
- Ubuntu增加一个用户并给普通用户赋予root权限的方法
1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户#passwd tommy //修改密码Changing pass ...
- ethcode
pragma solidity ^0.4.0;contract Ballot { struct Voter { uint weight; bool voted; uint8 vote; address ...
- HTML5离线存储之webstorage
html5在引入webStorage之前,主要用cookies. html5的webstorage 分两种:LocalStorage 和SessionStorage,两者的差别主要在生命周期不同. 1 ...
- iOS设计模式 - 原型
iOS设计模式 - 原型 原理图 说明 1. 原型模式指的是从一个已有的对象复制并创建出新的对象 2. 当一个类的实例之间存在差异,而这些差异仅是状态的若干组合,复制原型要比手工实例化更加方便 3. ...
- [EffectiveC++]item16:Use the same form in corresponding uses of new and delete
- 导出当前域内所有用户hash的技术整理
0x00目标: 导出当前域内所有用户的hash 0x01测试环境: 域控:server2008 r2 杀毒软件:已安装* 域控权限:可使用net use远程登陆,不使用3389 0x02测试方法: ( ...
- mac系统终端的color scheme配置和vim配置
一.配置终端 solarized http://ethanschoonover.com/solarized 简单配置脚本: #!/bin/sh git clone git://github.com/a ...
- MVC中使用过滤器做权限认证需要注意的地方
最近一项目接近尾声,正准备调试的时候发现一条原本不应该执行的SQL语句执行报错了,本就不应该执行,所以当然也就出错,找了一下,问题如下. 我这里是直接重写OnActionExecuting方法来达到目 ...
- JS实现快速排序算法
以下贴出两种实现方式,结果一样,但有些许的差别: 第一种: <script type="text/javascript"> var arr=[6,7,8,3,4,5,9 ...