效率低不是出在CASE里面,where条件索引OK?
帖执行计划看看为何效率低

解决方案 »

  1.   

    update table
    set 状态=1
    WHERE (种类='火车' and 编号='123')
    OR(种类='汽车' and 编号='458')
    OR(种类='导弹' and 编号='1578')
      

  2.   

    updata table set 状态=case when 种类=‘火车’ and 编号=‘123’ then 1 when 种类=‘汽车’ and 编号=‘458’ then 1 when 种类=‘导弹’ and 编号=‘1578’ then 0 else 状态 end
    又如何
      

  3.   

    天啊,然道你想要始终有三条受影响,不管符不符合?update table
    set 状态=case when 种类='火车' and 编号='123' then 1
      when 种类='汽车' and 编号='458' then 1
      when 种类='导弹' and 编号='1578' then 1
      else 状态
     end
    WHERE 编号 IN('123','458','1578')
      

  4.   

    updata table set 状态=case when 种类='火车' and 编号='123’ then 1 when 种类='汽车' and 编号='458’ then 1 when 种类='导弹' and 编号='1578’ then 1 else 状态 end
    where  种类='火车' and 编号='123’  or  种类='汽车' and 编号='458’  or 种类='导弹' and 编号='1578’ 
      

  5.   

    2楼的sql 不行吗?试试这个更灵活一些update table set 状态=b.状态
    from  table a join (
    select '火车'  种类,'123’ 编号,1 状态
    union all 
    select '汽车'  种类,'458’ 编号,1 状态
    union all 
    select '导弹'  种类,'11578’ 编号,1 状态) b on a.种类=b.种类 and a.编号=b.编号
      

  6.   


    不好意思,引号变全角了update table set 状态=b.状态
    from  table a join (
    select '火车'  种类,'123' 编号,1 状态
    union all 
    select '汽车'  种类,'458' 编号,1 状态
    union all 
    select '导弹'  种类,'11578' 编号,1 状态) b on a.种类=b.种类 and a.编号=b.编号