在有大量数据时 少用In(数据会丢失) 用left join 代替
2016-03-23 10:56
253 查看
select @From,
@To,
EffectiveDate,
GETDATE(),
Rate
from Config_Currency_ExchangeRate_Temp
where EffectiveDate not in (
select EffectiveDate
from Config_Currency_ExchangeRate
where EffectiveDate >=@BeginTime and
EffectiveDate <=@EndTime and
CIDFrom = @From and
CIDTo = @To
)
and EffectiveDate >=@BeginTime
and EffectiveDate <=@EndTime
and CIDFrom = @From
and CIDTo = @To
---------------------------------------------
---------------------------------------------
这种写法可以改为
select @From,
@To,
t.EffectiveDate,
GETDATE(),
t.Rate
from Config_Currency_ExchangeRate_Temp as t left join Config_Currency_ExchangeRate as r on t.EffectiveDate = r.EffectiveDate and t.CIDFrom = r.CIDFrom and t.CIDTo = r.CIDTo
where r.ID is null
and EffectiveDate >=@BeginTime
and EffectiveDate <=@EndTime
and CIDFrom = @From
and CIDTo = @To
@To,
EffectiveDate,
GETDATE(),
Rate
from Config_Currency_ExchangeRate_Temp
where EffectiveDate not in (
select EffectiveDate
from Config_Currency_ExchangeRate
where EffectiveDate >=@BeginTime and
EffectiveDate <=@EndTime and
CIDFrom = @From and
CIDTo = @To
)
and EffectiveDate >=@BeginTime
and EffectiveDate <=@EndTime
and CIDFrom = @From
and CIDTo = @To
---------------------------------------------
---------------------------------------------
这种写法可以改为
select @From,
@To,
t.EffectiveDate,
GETDATE(),
t.Rate
from Config_Currency_ExchangeRate_Temp as t left join Config_Currency_ExchangeRate as r on t.EffectiveDate = r.EffectiveDate and t.CIDFrom = r.CIDFrom and t.CIDTo = r.CIDTo
where r.ID is null
and EffectiveDate >=@BeginTime
and EffectiveDate <=@EndTime
and CIDFrom = @From
and CIDTo = @To
相关文章推荐
- oracle判断字符串中包函另外一个字符串
- 【Egret】 2D 使用中的一些疑难解决技巧!
- 241个jquery插件—jquery插件大全
- 新浪分享跳转网页返回/关闭网页按钮不显示的解决
- 聊天室实现
- Spring Web MVC详解
- 12、Extjs添加悬浮框
- owTforewoP.231
- iOS - @class ,#import" ",#import<>的区别
- 软件工程(进度条)
- 【R笔记】R语言进阶之4:数据整形(reshape)
- Django--models连表构建
- Linux初学者学习资料
- 我们为什么需要DTO(数据传输对象)
- ThinkPHP路由机制简介
- hdoj A + B Again 2057 (16进制加法)
- 使用Ping++为你的Wordpress博客一键集成支付功能的插件使用图文教程
- Android开发之Socket编程以及注意事项
- QT下的几种透明效果
- 在Ubuntu 12.04.4下 更新TL-WN821N无线网卡驱动