https://blog.csdn.net/babyfish13/article/details/78082844

*********************************************************************

样式1:

update xcs_user_credit_score a1,xcs_user_credit_score a2
set a1.user_currday_score=a1.user_currday_increment_score+a2.user_currday_score
where a1.pt_day='2017-09-20' and a2.pt_day='2017-09-19'
and a1.uid=a2.uid;

样式2:

    update xcs_user_credit_score a1
inner join xcs_user_credit_score a2
on a1.uid=a2.uid
set a1.user_currday_score=a1.user_currday_increment_score+a2.user_currday_score
where a1.pt_day='2017-09-20' and a2.pt_day='2017-09-19'
;

突然发现mysql的一些sql语法也很神奇,像这样式的sql语句,在oracle中是行不通的,需要其他的形式。
另外的几个例子:

    --sub:
update xcs_user_credit_score a1,xcs_user_credit_score a2
set a1.user_currday_score=(case when a2.user_currday_score-10>0 then a2.user_currday_score-10 else 0 end)
where a1.pt_day='2017-09-20' and a2.pt_day='2017-09-19'
and a1.uid=a2.uid
and (a1.seqing_score=0 and a1.user_silent_score=0 and a1.jubao_score=0 and a1.chengpaopao_score=0 and a1.weifan_score=0 and a1.upper_manage_score=0 and a1.pay_active_score=0 and a1.view_active_score=0 and a1.message_active_score=0 and a1.gift_active_score=0 and a1.live_active_score=0)
and a2.user_currday_score>0
; --plus:
update xcs_user_credit_score a1,xcs_user_credit_score a2
set a1.user_currday_score=(case when a1.user_currday_score+10<0 then a1.user_currday_score+10 else 0 end)
where a1.pt_day='2017-09-20' and a2.pt_day='2017-09-19'
and a1.uid=a2.uid
and (a1.seqing_score=0 and a1.user_silent_score=0 and a1.jubao_score=0 and a1.chengpaopao_score=0 and a1.weifan_score=0)
and a1.user_currday_score<0
;

mysql关联更新update的更多相关文章

  1. Mysql 批量更新update的表与表之间操作

    Mysql 批量更新update的表与表之间操作 一.方法一 使用User2表数据更新User表: update User as a ,User2 as b set a.role_id=b.set_v ...

  2. mysql批量更新update中的锁表机制

    mysql的行锁是通过索引加载的,即行锁是加在索引响应的行上的,要是对应的SQL语句没有走索引,则会全表扫描,行锁则无法实现,取而代之的是表锁. CREATE TABLE SIMPLE_USER( I ...

  3. mysql关联更新

    update tb_sdd_info a,tb_bnm_evian_info b set a.username=b.username where a.username=b.memberno and  ...

  4. sql server 多表关联更新 update

    update a set a.KSMC = b.name from JC_KSXXB a inner join chisdb_ymyy..zd_unit_code b on a.KSDM = b.co ...

  5. 关联更新 Update

    Update a set a.Manage_FunctID=b.Manage_FunctID   From Manage_PageUrl a   Left join Manage_ButtonBar ...

  6. mysql关联更新表

    UPDATE ecm_store s LEFT JOIN (SELECT store_id, COUNT(goods_id) AS goods_count FROM ecm_goods GROUP B ...

  7. sqlserver update join 多关联更新

    由于程序bug,导致之前很多数据入库后信息不全,好在有基础信息表,可以通过基础信息表更新缺失字段信息 1.通过 inner join语法实现多关联更新 update a set a.name = b. ...

  8. oracle学习笔记:update一整列 关联更新

    普通的 update 都是根据条件来对部分列的内容进行修改,用法如下: update temp_cwh_table set name = 'xxx' where id = 1; 假设现在有2张表:A. ...

  9. SQL使用之关联更新、批量插入

    使用场景 某个字段数据异常,利用另外一张表同步修改该表异常字段的数据; 关联更新 UPDATE tableName1 AS t1 LEFT JOIN tableName12 AS t2 ON t1.x ...

随机推荐

  1. openssl req 证书请求及自签名证书

    介绍 openssl req 用于生成证书请求,以让第三方权威机构CA来签发,生成我们需要的证书.req 命令也可以调用x509命令,以进行格式转换及显示证书文件中的text,modulus等信息.如 ...

  2. ubuntu(14.04) 下安装yaf拓展

    #wget http://pecl.PHP.net/get/yaf-2.2.9.tgz #tar zxvf yaf-.tgz #cd yaf- [root@bogon yaf-]# whereis p ...

  3. 解决UEditor将div标签换成p标签的问题

    原文链接 将设计排版好的页面html代码上传到数据库,再读取出来的时候发现所有的div都被替换成了p标签. 解决方法: 首先在ueditor.all.js文件内搜索allowDivTransToP,找 ...

  4. 【Android】详解Android的menu菜单

    在软件应用过程中,菜单的存在是必不可少的,我这次讲一下,我对android菜单的一个基础做法吧 Android的菜单分为三种类型:选项菜单(Option Menu).上下文菜单(Context Men ...

  5. jQuery.ajax发送image请求格式

    1\请求端 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head run ...

  6. log4j(二)——如何控制日志信息的输出?

    一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 二:先看栗子再来下结论 import org.apache.log4j.*; import test.log4j.bean ...

  7. [aaronyang] nodejs学习-mongodb[1]

    1.资源提供与安装(ayjs.net) 学习说明:nodejs还是在非windows环境下操作好,所以一切还是 当前时间:2014年12月06日aaronyang 官网地址:www.mongodb.o ...

  8. mongoDB 32位 安装包地址

    https://www.mongodb.org/dl/win32/i386 http://downloads.mongodb.org/win32/mongodb-win32-i386-3.2.4-si ...

  9. MySQL -- Fast Index Creation

    1.fast index creation简介 MySQL5.5之后,对innodb表创建或删除辅助索引的效率提升了很多,即增加了新的功能fast index creation.因为MySQL5.5之 ...

  10. android:fitsSystemWindows属性的用法

    属性说明 fitsSystemWindows属性可以让view根据系统窗口来调整自己的布局:简单点说就是我们在设置应用布局时是否考虑系统窗口布局,这里系统窗口包括系统状态栏.导航栏.输入法等,包括一些 ...