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

  • 相关阅读:
    最长回文子序列---DP
    最长回文子串(暴力破解)
    两数相加
    多数元素
    MPI集群搭建
    字符串截取子串(Java substring , indexOf)
    JDK和环境配置,eclipse安装与使用
    ubantu上面 NFS服务器安装
    Django中间件的应用
    Django的url路由系统简介
  • 原文地址:https://www.cnblogs.com/zhc088/p/1686284.html
Copyright © 2011-2022 走看看