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 ...
随机推荐
- 【Android Api 翻译1】Android Texting(2)Testing Fundamentals 测试基础篇
Testing Fundamentals The Android testing framework, an integral part of the development environment, ...
- UICollectionView 简单应用和实际操作
1.网格视图 UICollectionView 网格布局 UICollectionViewFlowLayout系统图自带网格布局 系统自带的网格布局 UICollectionViewFl ...
- vmware workstation 网络管理
其实在VMware Workstation下的网络管理是一个比较复杂的东西,如果你不是很了解他的网络,也许你的实验的时候,尤其是涉及到NAT转换.路由等问题的时候,你可能不知道从哪里下手,这时候你可能 ...
- oracle-同义词Synonyms + 用户访问控制(grant 和 revoke)
同义词(Synonyms) 创建同义词: 语法 CREATE [PUBLIC] SYNONYM synonym FOR object; CREATE SYNONYM ...
- Sharepoint 2013 安装部署系列篇 第二篇 -- SQL集群安装
第一部分 系统集群安装. 第三部分 安装和配置网络负载均衡在前端web服务器 第四部分 安装和配置sharepoint 场(三层拓扑部署) 以下图片均为sharepoint 2010..由于本人的笔记 ...
- JavaScript:exec()方法的用法及说明
最近在看某知名js框架的源码,突然间发现自己对exec()方法竟然不太理解,然后就仔细的分析了一下这个方法 下面贴个exec()方法使用的代码出来 rquickExpr = /^(?:\s*(< ...
- PHP与MySQL中编码的设置
php代码 header("Content-type:text/html;Charset=utf8"); myql_query("set names utf8" ...
- LINQ to SQL 语句(2)之 Select/Distinct
LINQ to SQL 语句(2)之 Select/Distinct [1] Select 介绍 1 [2] Select 介绍 2 [3] Select 介绍 3 和 Distinct 介绍 Se ...
- windows下,python+scrapy环境搭建
•安装lxml(官网给出的地址http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml,下载whl文件安装) •安装zope.interface https:// ...
- 2015-0306—DataLList
DataList具有repeater的所有功能,不同的是DataList自动将模板绘制成为一个表格,每一行数据都绘制成<tr>. 一.SQL的准备工作: 按照以下代码创建: create ...