Merging into a Table: Example
Merging into a Table: Example The following example uses the bonuses table in the sample schema oe with a default bonus of 100. It then inserts into the bonuses table all employees who made sales, based on the sales_rep_id column of the oe.orders table. Finally, the human resources manager decides that employees with a salary of $8000 or less should receive a bonus. Those who have not made sales get a bonus of 1% of their salary. Those who already made sales get an increase in their bonus equal to 1% of their salary. The MERGE statement implements these changes in one step:
CREATE TABLE bonuses (employee_id NUMBER, bonus NUMBER DEFAULT 100); INSERT INTO bonuses(employee_id)
(SELECT e.employee_id FROM employees e, orders o
WHERE e.employee_id = o.sales_rep_id
GROUP BY e.employee_id); SELECT * FROM bonuses ORDER BY employee_id; EMPLOYEE_ID BONUS
----------- ----------
153 100
154 100
155 100
156 100
158 100
159 100
160 100
161 100
163 100 MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000); SELECT * FROM bonuses ORDER BY employee_id; EMPLOYEE_ID BONUS
----------- ----------
153 180
154 175
155 170
159 180
160 175
161 170
179 620
173 610
165 680
166 640
164 720
172 730
167 620
171 740 http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF55042
Merging into a Table: Example的更多相关文章
- [Hive - LanguageManual] Alter Table/Partition/Column
Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...
- mysql也有complex view merging 这个特性(5.6 , 5.7)
出处:黑洞中的奇点 的博客 http://www.cnblogs.com/kelvin19840813/ 您的支持是对博主最大的鼓励,感谢您的认真阅读.本文版权归作者所有,欢迎转载,但请保留该声明. ...
- 归并排序(Merging Sort)
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- NAND Flash Bad Block Table
转:http://wiki.laptop.org/go/NAND_Flash_Bad_Block_Table 1 OLPC NAND Bad Block Management 1.1 Introduc ...
- 散列表(hash table)——算法导论(13)
1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...
- React使用antd Table生成层级多选组件
一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...
- 创建几个常用table展示方式插件
这次和大家分享的是自己写的一个table常用几种展示格式的js插件取名为(table-shenniu),样式使用的是bootstrap.min.css,还需要引用jquery.min.js包,这个插件 ...
- html中table边框属性
1.向右(横向)合并: <td colspan="5"><span>后台管理系统</span></td> 2.向下(纵向)合并: & ...
- MySQL中You can't specify target table for update in FROM clause一场
mysql中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值 ...
随机推荐
- Handle exception in ServiceBase.OnStart method
https://docs.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.onstart?view=netframew ...
- SQL 优化记录
1. 对Where 语句的法则 1.1 避免在WHERE子句中使用in,not in,or 或者having. 可以使用 exist 和not exist代替 in和not in. 可以使用表链接代 ...
- 套接字(socket)与socket 编程
字节序: 主机字节序(host byte order):不同的主机有不同的字节序,x86:小端: 网络字节序(network byte order):大端字节序: 0. 什么是套接字 套接字是网络进程 ...
- linux更换阿里云的源的shell脚本
#!/bin/bash##########################################Function: update source#Usage: bash update_sour ...
- MSSQL:查看作业情况
select j.name 'Job名', j.description '描述', j.ENABLED job_enabled, cast(js.last_r ...
- 5.17领扣--Arrays.copyOf()方法
?? 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同 ...
- 在Winform中怎么实现图片的旋转,比如说实现仪表盘功能,看代码吧,看太不懂的欢迎问
; //旋转的角度 //Timer定时器 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; ...
- Java中final、finally、finalize的区别与用法
1.简单区别:final用于声明属性,方法和类,分别表示属性不可交变,方法不可覆盖,类不可继承.finally是异常处理语句结构的一部分,表示总是执行.finalize是Object类的一个方法,在垃 ...
- 笔记 — 动画效果(Css3)
/** * animation-name: 调用 @keyframes 所定义的动画 * animation-duration: 动画周期所花费的时间长度 * animation-timing-fun ...
- 关于AS使用git的那些奇葩事儿
首先致谢: http://blog.csdn.net/a10615/article/details/52135617, 我们不生产代码, 我们只做大自然的搬运工! 总结 1. 首次无法push问题: ...