SQLserver Delete from where 与Oracle delete from where 的差异
1.SQLserver 版本:
select @@version;
Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
Dec 28 2012 20:23:12
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
2.需求场景,生产系统中的数据为刷卡记录,存在重复的情况,现在需要删除重复的数据。
具体判别重复的方式为:同一卡号、同一消费金额、同一消费窗口、两条消费记录的时间差小于30秒则认为是重复的。样例数据如下:
2012210856 9.00 2016-03-02 11:47:05.000 消费 后勤集团\饮食中心\桂香园餐厅新\二楼\黑椒鸡柳饭 本专科生 7686
2012210856 9.00 2016-03-02 11:47:30.000 消费 后勤集团\饮食中心\桂香园餐厅新\二楼\黑椒鸡柳饭 本专科生 7687
2012210856 9.00 2016-03-02 11:47:48.000 消费 后勤集团\饮食中心\桂香园餐厅新\二楼\黑椒鸡柳饭 本专科生 7688
3.查询重复记录
select a.* from dbo.ODS_CCNU_zengx_distinct a inner join dbo.ODS_CCNU_zengx_distinct b
on a.smt_salaryno = b.smt_salaryno --同一卡号
and a.smt_transmoney=b.smt_transmoney --同一消费金额
and a.smt_org_name = b.smt_org_name --同一消费窗口
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)>=0
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)<30 --时间间隔为30秒之内
and a.rownum_distinct != b.rownum_distinct
order by a.smt_salaryno,a.smt_dealdatetime ;
或者这样
select a.* from [dbo].ODS_CCNU_zengx_distinct a
where exists( select 1 from [dbo].ODS_CCNU_zengx_distinct b
where a.smt_salaryno = b.smt_salaryno --同一卡号
and a.smt_transmoney=b.smt_transmoney --同一消费金额
and a.smt_org_name = b.smt_org_name --同一消费窗口
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)>=0
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)<30 --时间间隔为30秒之内
and a.rownum_distinct != b.rownum_distinct
)
order by a.smt_salaryno,a.smt_dealdatetime ;
删除重复记录,如果在oracle中可以这样写
delete from dbo.ODS_CCNU_zengx_distinct a
where exists( select 1 from dbo.ODS_CCNU_zengx_distinct b
where a.smt_salaryno = b.smt_salaryno --同一卡号
and a.smt_transmoney=b.smt_transmoney --同一消费金额
and a.smt_org_name = b.smt_org_name --同一消费窗口
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)>0
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)<30 --时间间隔为30秒之内
and a.rownum_distinct != b.rownum_distinct
);
但是SQLserver不支持这种写法,反而支持连接的方式(oracle不支持inner join 的方式)
delete a from dbo.ODS_CCNU_zengx_distinct a inner join dbo.ODS_CCNU_zengx_distinct b
on a.smt_salaryno = b.smt_salaryno --同一卡号
and a.smt_transmoney=b.smt_transmoney --同一消费金额
and a.smt_org_name = b.smt_org_name --同一消费窗口
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)>=0
and datediff(ss,a.smt_dealdatetime,b.smt_dealdatetime)<30 --时间间隔为30秒之内
and a.rownum_distinct != b.rownum_distinct;
SQLserver Delete from where 与Oracle delete from where 的差异的更多相关文章
- Oracle delete input与delete all input
oracle官方文档提示:If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN would have on ...
- Oracle delete和truncate实践操作之一
实践说明 本文章主要记录在Oracle中,delete和truncate进行数据删除之后,如何进行数据恢复.由于网上对delete和truncate的区别说明较多,此处不过多介绍两者区别. 注:由于环 ...
- Sqlserver通过链接服务器访问Oracle的那些事儿
前言: 1.不经历风雨,怎能见彩虹. 2.充分利用BaiDu.google等搜索引擎查找资料并整合分析! 3.世上无难事只怕有心人! 本文由来:笔者在研究SQLSERVER链接服务器到oracle并使 ...
- mysql没有delete操作,那是delete from操作,
1.mysql没有delete操作,那是delete from操作, 2.DELETE FROM table_name [WHERE Clause]
- C++ new operator, delete operator, operator new, operator delete, new placement
http://www.younfor.com/cpp-new-placement-new-operator-new.html http://www.cnblogs.com/luxiaoxun/arch ...
- 【转】Sqlserver通过链接服务器访问Oracle的那些事儿!
原文:http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 前言:1.不经历风雨,怎能见彩虹.2.充分利用BaiDu.google等搜索引擎查找资料 ...
- Sqlserver通过链接服务器访问Oracle的解决办法
转自http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 一.创建sqlserver链接服务(sqlserver链接oracle) 首先sqlse ...
- C++中的new/delete与operator new/operator delete
new operator/delete operator就是new和delete操作符,而operator new/operator delete是函数. new operator(1)调用opera ...
- C++ new和delete实现原理——new和delete最终调用malloc和free
new和delete最终调用malloc和free,关于malloc和free实现原理参见这篇文章: http://blog.csdn.net/passion_wu128/article/detail ...
随机推荐
- ArcGIS Engine断开其他ArcSDE用户连接的解决方案
来自:http://blog.csdn.net/linghe301/article/details/38925481 最近有很多用户咨询在ArcGIS Engine中希望能够实现断开其他客户端连接Ar ...
- Android小项目之四 自动更新检查的逻辑
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...
- 《UNIX环境高级编程》学习心得 三
输入和输出 1.文件描述符 文件描述符(file descriptor)可以理解为内核在某个进程中访问一个文件时,内核向进程返回的一个非负整数.在内核使用open或creat打开一个现有文件或者创建一 ...
- Mac和Linux下测试端口是否存活一法[转载]
测试端口存活的最常用的方法是telnet $telnet 127.0.0.1 80 不过这个方法有一个不方便的地方:连接成功后会进入交互模式,需要按 ctrl + ] 和 q 才能退出. 后来,经过网 ...
- iOS加入百度地图的几个问题
1.其中一个.m文件要改成.mm文件 2.plist文件必须包含两项 Bundle display name-值不能为空 NSLocationWhenInUseUsageDescription-值可以 ...
- 【转】关于loadrunner中设置进程和线程的区别
loadrunner中,在进行运行设置中有一项选择,是按进程运行Vuser或按线程运行Vuser?下面进行分别来讲: 1.按进程运行Vuser:Controller将使用驱动程序mdrv运行Vuser ...
- 前台传到servlet的乱码问题要怎么处理
- 【CSS3】---@font-face
- C语言经典参考书籍
<C程序设计语言> Brian W.Kernighan,Dennis M.Ritchie 编著:C语言的开山之作.C程序员应该人手一本. <C语言参考手册> Samuel P. ...
- Part 53 to 55 Talking about Reflection in C#
Part 53 Reflection in C# Part 54 Reflection Example here is the code private void btnDiscover_Click( ...