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 ...
随机推荐
- Java Map接口
Map接口映射唯一键的值.一个关键是,要使用在日后检索值对象. 给定一个键和一个值,可以在一个Map对象存储的值.后的值被存储时,可以使用它的键检索. 抛出一个NoSuchElementExcepti ...
- Android(java)学习笔记62:继承Thread类创建线程类
package cn.itcast_02; /* * 该类要重写run()方法,为什么呢? * 不是类中的所有代码都需要被线程执行的. * 而这个时候,为了区分哪些代码能够被线程执行,java提供了T ...
- Ubuntu15.10使用mysql
安装 sudo apt-get install mysql-server sudo apt-get install mysql-client sudo apt-get install libmysql ...
- 《UNIX环境高级编程》学习心得 二
窝萌来看我们看到这本书里的第一个程序 #include "apue.h" #include <dirent.h> int main(int argc, char *ar ...
- 设置navigationBar上面的item
//创建UIBarButtonItem UIBarButtonItem * rightButton = [[UIBarButtonItem alloc]initWithBarButtonSystemI ...
- C# 序列化JavaScriptSerializer
1.首先引入 System.Web.Extensions.dll 2.写入命名空间 System.Web.Script.Serialization 3.实现序列化. class Program { s ...
- Linux 网络设备驱动程序设计(2)
二.回环网卡的程序设计 /*************************** *******回环网卡的驱动程序*** ***********吕晓宁*********** *********2015 ...
- html2canvas 踩坑总结
需求:将html表格导出为图片,表格可以自己编辑数据,并适配各种屏幕大小.上网搜了下,找到了html2canvas,一开始使用的是最新版0.5.0,最终因为需要支持自定义div编辑框自动换行选择了v0 ...
- nodejs5-package.json
name:包名,唯一,由小写字符.数字和下划线组成,不能有空格 preferglobal:是否支持全局安装,true表示支持 descrition:描述 version:版本号 author:作者信息 ...
- Linux中Bash发现重大安全漏洞修改方法
北京时间9月25日消息,Linux用户今天又得到了一个“惊喜”!Red Hat安全团队在 Linux 中广泛使用的Bash shell中发现了一个隐晦而危险的安全漏洞.该漏洞被称为“Bash Bug” ...