ORACLE外连接实例
--查询各个部门工资范围,按照1000~2000,2000~3000.。。。这样的格式显示人数
-------------------方法一
select
dept.dname ,nvl(ano,0) "1000以下",nvl(dno,0) "1000~2000",
nvl(bno,0) "2000~3000",nvl(cno,0) "3000以上"
from dept,
(select ano,"1000~2000" dno,"2000~3000" bno,nvl("3000以上",0) cno,f.deptno from
(select ano,"1000~2000","2000~3000",e.deptno from
(select nvl("1000以下",0) ano,"1000~2000",b.deptno from
(select count(sal) "1000以下" , deptno from emp where sal<1000 group by deptno) a ,
(select count(ename) "1000~2000",deptno from emp where sal>=1000 and sal<2000 group by deptno) b
where a.deptno(+) = b.deptno) e,
(select count(ename) "2000~3000",deptno from emp where sal>=2000 and sal<=3000 group by deptno) c
where e.deptno=c.deptno(+)) f,
(select count(ename) "3000以上",deptno from emp where sal>3000group by deptno) d
where f.deptno = d.deptno(+)) g
where g.deptno(+)=dept.deptno
---------------------------------------------------------------------------------------------------------------------
--方法二
select nvl(ano,0) "1000以下",nvl(bno,0) "1000~2000",nvl(cno,0) "2000~3000",nvl(dno,0) "3000以上",dept.dname from dept
full join
(select count(sal) ano , deptno from emp where sal<1000 group by deptno) a
on a.deptno = dept.deptno
full join
(select count(ename) bno,deptno from emp where sal>=1000 and sal<2000 group by deptno) b
on dept.deptno = b.deptno
full join
(select count(ename) cno,deptno from emp where sal>=2000 and sal<=3000 group by deptno) c
on dept.deptno = c.deptno
full join
(select count(ename) dno,deptno from emp where sal>3000group by deptno) d
on dept.deptno = d.deptno
运行结果:

综合实例
create table test1
("姓名" varchar2(20),"年龄" number(6),"籍贯" varchar2(40),"婚姻状况" varchar2(4),"性别" varchar2(2)); --修改字段类型 alter table 表名 modify(字段名 新数据类型(大小))(不能有数据)
alter table test1 modify ("年龄" number (4)); insert into test1 values ('张强',23,'宝鸡','未婚','男');
insert into test1 values ('张戈',25,'西安','未婚','男');
insert into test1 values ('张敏',35,'临潼','已婚','女');
insert into test1 values ('张超',57,'渭南','已婚','男');
insert into test1 values ('张灵',20,'武功','未婚','女');
insert into test1 values ('张林',18,'榆林','未婚','男');
insert into test1 values ('张宝',1208,'黄巾','未知','男');
insert into test1 values ('张角',1210,'黄巾','未知','男'); update test1 set "婚姻状况" = '丧偶' where "姓名"='张宝';
--添加字段 alter table 表名 add(字段名 数据类型(大小))
alter table test1 add ("结婚次数" number(3)); update test1 set "结婚次数"="年龄"/80 where "姓名"='张角';
update test1 set "结婚次数"=0 where "婚姻状况"='未婚'; update test1 set "结婚次数"=2 where "姓名" in('张敏','张超'); --删除字段 alter table 表名 drop column 字段名
alter table test1 add (canspel char(1)); update test1 set canspel = 'y' where "年龄"<30;
update test1 set canspel = 'n' where "年龄">=30;
alter table test1 drop column canspel;
rename test1 to "古今人物婚姻调查";
select *from "古今人物婚姻调查";
alter session set nls_date_format='yyyy-mm-dd';
alter table "古今人物婚姻调查" add ("调查日期" date default sysdate);
alter table "古今人物婚姻调查" drop column "调查日期";
update "古今人物婚姻调查" set "调查日期"='2013-09-11' where "年龄"<100;
update "古今人物婚姻调查" set "调查日期"='-101-12-01' where "年龄">100;
ORACLE外连接实例的更多相关文章
- oracle 外连接以及用on和where 的区别
Oracle 外连接(OUTER JOIN)包括以下: 左外连接(左边的表不加限制) 右外连接(右边的表不加限制) 全外连接(左右两表都不加限制) 对应SQL:LEFT/RIGHT/FULL OUT ...
- Oracle 外连接和 (+)号的用法
对于外连接,Oracle中可以使用“(+)”来表示,9i可以使用LEFT/RIGHT/FULL OUTER JOIN,下面将配合实例一一介绍.1. LEFT OUTER JOIN:左外关联 SELEC ...
- oracle——外连接查询
一.问题描述 有时我们为了保留某个表中的数据,而该表中的数据在另外一个关联表中未必都存在对应,此时就应该试用外连接查询. 比如:两个表,产品表和子产品表 注:子产品的parent_product_id ...
- mysql中的内连接,外连接实例详解
内连接: 只连接匹配的行左外连接: 包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行右外连接: 包含右边表的全部行(不管左边的表中是否存在与它们匹配的行),以及左边 ...
- Oracle外连接与条件的组合
由于很少使用SQL 92语法,今天写个outer join的时候被搞晕了.参考了一些例子后整理如下.总结,"inter join on"中的条件是对table进行joining的r ...
- Oracle 左连接、右连接、全外连接、(+)号作用
分类: Oracle Oracle 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 外连接(Outer ...
- Oracle 左连接、右连接、全外连接、(+)号作用、inner join(等值连接) (转载)
Oracle 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 外连接(Outer Join) oute ...
- Oracle左连接、右连接、全外连接
Oracle 外连接 (1)左外连接 (左边的表不加限制)(2)右外连接(右边的表不加限制)(3)全外连接(左右两表都不加限制) 外连接(Outer Join) outer join则会返回每个满足 ...
- Oracle左连接、右连接、全外连接以及(+)号用法(转)
+:与附带的字段相连,和“+”相连的字段值,不管是否存在,都会展示 也就是带上相连接的字段 有数据了就显示,没数据就显示为null Oracle 外连接(OUTER JOIN) 左外连接(左边的表不 ...
随机推荐
- Leetcode 1020. 将数组分成和相等的三个部分
1020. 将数组分成和相等的三个部分 显示英文描述 我的提交返回竞赛 用户通过次数321 用户尝试次数401 通过次数324 提交次数883 题目难度Easy 给定一个整数数组 A,只有我们可 ...
- Linux下切换使用两个版本的JDK
Linux下切换使用两个版本的JDK 我这里原来已经配置好过一个1.7版本的jdk. 输出命令: java -version [root@hu-hadoop1 sbin]# java -version ...
- bool类型为什么可以当做int
实际上bool型变量占用了一个字节的内存,当值为false的时候,实际存储的是0x00,为true时实际存储的是0x01,因此可以作为int整型使用 bool型只分0与非0,0为false,其余的包括 ...
- 小程序 wepy wx.createAnimation 向右滑动渐入渐出
<style lang="less"> .animation { width: 100vw; height: 100vh; opacity: 0; background ...
- python字符串内建函数
- ubuntu shell编程笔记
and 命令 if [ A -a B ] then else fi while [ ] do done set command set these are parameters $1 s ...
- Boost中的网络库ASIO,nginx
boost C++ 本身就是跨平台的,在Linux.Unix.Windos上都可以使用. Boost.Asio 针对网络编程,很多服务端C++开发使用此库. 这个库在以下的平台和编译器上测试通过: ...
- 分析图第二讲导出图片和后期PS5.12
导出渲染的白模加上EXTRATEX.再导出一张“消隐”样式的模型图片.就是线稿图. 再导出一张着色显示图,并去掉边线.,用于后期PS选择范围用. 把这几张图全都导入ps. 渲染图的阴影面是灰色的,示例 ...
- 【Loadrunner_Http接口】使用Loadrunner对天气信息的接口编写脚本
方法一:使用get请求 Action() { //http接口访问,get请求 web_url("www.abc.com", "URL=http://v.juhe.cn/ ...
- ssh三大框架整合
spring+struts2+hibernate 参考1:数据库为oracle http://takeme.iteye.com/blog/1678268 参考2:数据库为mysql http://bl ...