您的位置:首页 > 其它

在有大量数据时 少用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: