zoukankan      html  css  js  c++  java
  • SQL: update set from

    在 SQL 中,表连接(left join、right join、inner join 等)常常用于 select 语句,其实在 SQL 语法中,这些连接也是可以用于 update 和 delete 语句的,在这些语句中使用 join 还常常得到事半功倍的效果。 

    update 把一个表中的数据 更新到另一个表中  

    下面是这样一个例子:

    两个表a、b,想使b中的memo字段值等于a表中对应id的name值  
      表a:id,name  
                1       王  
                2       李  
                3       张  
      表b:id,ClientName   
                1        
                2  
                3  
    (MS SQL Server)语句:update   b  set   ClientName   =   a.name   from   a,b   where   a.id   =   b.id  

    update obill_invoice set Cost=t1.Cost,Fee=t1.Fee from obill_invoice t2 inner join
    (
       select m.obillid,m.invoiceno,sum(c.cost) as 'Cost',sum(c.fee) as 'Fee' from obill_recipe_master m   --14871 
       inner join obill_recipe_Detail
       c on m.recipeno=c.recipeno and m.obillid=c.obillid and m.visitno=c.visitno and c.cost<>0
       group by m.obillid,invoiceno
    ) t1
     
     on t1.oBillID=t2.oBillID and t1.invoiceno=t2.invoiceno

    where t1.Cost <> t2.Cost

  • 相关阅读:
    Concurrent
    Java多线程状态切换
    Java中volatile如何保证long和double的原子性操作
    协程与线程
    线程饥饿
    线程活锁
    线程死锁
    Java Thread之start和run方法的区别
    ThreadLocal内存泄漏
    interrupt和interrupted和isInterrupted的区别
  • 原文地址:https://www.cnblogs.com/zhc088/p/1686284.html
Copyright © 2011-2022 走看看