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 ...
随机推荐
- 【阿里云产品公测】ACE、BAE及SAE云引擎对比评测
作者:阿里云用户bailimei 先前我已发布一篇关于ACE的评测,在跟朋友聊天的时候我们讨论了目前市面上的三款云引擎产品,这三家的云引擎我都有在用,今天有时间顺便写篇关于阿里云ACE.百度BAE和新 ...
- WCF架构日记-1
WCF功能很强大,但是真的能把其中的原理说清楚,对于我比较困难,今天对之前的笔记总结一下: 首先WCF的契约可以总结为四大类:消息契约.数据契约.服务契约.错误处理契约. [客户端处理是如何处 ...
- Android中Handler作用
在Android的UI开发中,我们经常会使用Handler来控制主UI程序的界面变化.有关Handler的作用,我们总结为:与其他线程协同工作,接收其他线程的消息并通过接收到的消息更新主UI线程的内容 ...
- 实现MVC4多级Views目录
建立自己MyViewEngine类让他继承RazorViewEngine,之后在构造函数里面写入设置视图位置格式代码如下: public class MyViewEngine : RazorViewE ...
- ionic 中使用ion-slide-box
ion-slide-box 用法: <ion-slide-box class="slide" auto-play="true" does-continue ...
- [转]15 个顶级 HTML5 游戏引擎
本文转自:http://www.open-open.com/news/view/13874db 1) HTML5 Game Engine Construct 2 is a leading high q ...
- codeforces 434B B. Nanami's Digital Board(分治)
题目链接: B. Nanami's Digital Board time limit per test 1 second memory limit per test 256 megabytes inp ...
- Linux Centos 怎么安装更新根证书实现支持https访问
其实很简单就是一个命令: mozroots --import --ask-remove 或者使用: sudo update-ca-certificates
- flv视频播放器代码
<div class="txt1"> <script type="text/javascript"> var swf_width=307 ...
- Java开发从零开始填坑
开始学习Java,感觉较.NET知识更零碎一些,所以开个帖子把自己踩过的坑记录下来,都是边边角角网上不容易找到的东西. 1.java命令格式:>cd %parent-of-pakadgePath ...