zoukankan      html  css  js  c++  java
  • 在有大量数据时 少用In(数据会丢失) 用left join 代替

    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

  • 相关阅读:
    Python基础07
    python基础06
    python基础05
    python基础04
    python基础03
    python基础02
    python组件之wtforms
    PythonWeb框架之Flask
    Linux下yum安装Redis
    在vuex的mutations中使用vue的小技巧
  • 原文地址:https://www.cnblogs.com/dwuge/p/5310142.html
Copyright © 2011-2022 走看看