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

  • 相关阅读:
    配置Log4j(非常具体)
    System.Net.WebClient.cs
    Code:获取指定汉字的首字母
    DBS:目录
    Jasper:推送 API
    Jasper-template
    Code:Base64 编码/解码
    DCloud-HTML5+:5+ App开发入门指南
    DCloud-HTML5+:barcode
    Nuget-QRCode:QRCoder
  • 原文地址:https://www.cnblogs.com/zhc088/p/1686284.html
Copyright © 2011-2022 走看看