mysql关联更新update
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的更多相关文章
- Mysql 批量更新update的表与表之间操作
Mysql 批量更新update的表与表之间操作 一.方法一 使用User2表数据更新User表: update User as a ,User2 as b set a.role_id=b.set_v ...
- mysql批量更新update中的锁表机制
mysql的行锁是通过索引加载的,即行锁是加在索引响应的行上的,要是对应的SQL语句没有走索引,则会全表扫描,行锁则无法实现,取而代之的是表锁. CREATE TABLE SIMPLE_USER( I ...
- mysql关联更新
update tb_sdd_info a,tb_bnm_evian_info b set a.username=b.username where a.username=b.memberno and ...
- 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 ...
- 关联更新 Update
Update a set a.Manage_FunctID=b.Manage_FunctID From Manage_PageUrl a Left join Manage_ButtonBar ...
- mysql关联更新表
UPDATE ecm_store s LEFT JOIN (SELECT store_id, COUNT(goods_id) AS goods_count FROM ecm_goods GROUP B ...
- sqlserver update join 多关联更新
由于程序bug,导致之前很多数据入库后信息不全,好在有基础信息表,可以通过基础信息表更新缺失字段信息 1.通过 inner join语法实现多关联更新 update a set a.name = b. ...
- oracle学习笔记:update一整列 关联更新
普通的 update 都是根据条件来对部分列的内容进行修改,用法如下: update temp_cwh_table set name = 'xxx' where id = 1; 假设现在有2张表:A. ...
- SQL使用之关联更新、批量插入
使用场景 某个字段数据异常,利用另外一张表同步修改该表异常字段的数据; 关联更新 UPDATE tableName1 AS t1 LEFT JOIN tableName12 AS t2 ON t1.x ...
随机推荐
- keras embeding设置初始值的两种方式
随机初始化Embedding from keras.models import Sequential from keras.layers import Embedding import numpy a ...
- maven Missing artifact com.sun:tools:jar:1.5.0
转自:http://blog.csdn.net/caolaosanahnu/article/details/7918929 http://zuoshahao.com/work/others/missi ...
- 零行代码为 App 添加异常加载占位图
前文提要 近期准备重构项目,需要重写一些通用模块,正巧需要设置App异常加载占位图的问题,心血来潮设想是否可以零行代码解决此问题,特在此分享实现思路. 思路分享 对于App占位图,通常需要考虑的控件有 ...
- string与char*的转换方法
c_str函数的返回值是const char*的,不能直接赋值给char*,所以就需要我们进行相应的操作转化,下面就是这一转化过程. c++语言提供了两种字符串实现,其中较原始的一种只是字符串的c语言 ...
- Swift 构造与析构
前言 与 OC 一样,Swift 中也存在构造和析构过程.不同的是,OC 中的构造方法和析构方法只是普通的方法,而 Swift 中构造器和析构器是一种特殊的结构. 1.构造器 在 Swift 中,类或 ...
- Paros 网络抓包工具
1.Paros 简介 Paros 是一款数据抓包工具. 官网下载地址 Paros 其它下载地址 Paros v3.2.13 for Mac,密码:e4hk. 2.使用方法 2.1 打开 Paros 打 ...
- 【转】不要去SeaWorld
不要去SeaWorld 很多人喜欢海洋动物,比如海豚和“杀人鲸”(orca),但是我建议不要去海洋世界看它们.海豚和杀人鲸都是有灵性的,跟人类的智慧很接近,而且对人极其友好的动物.“杀人鲸”名字吓人, ...
- 【转】Tesla Model X的车门设计问题
Tesla Model X的车门设计问题 Tesla即将推出的SUV(Model X),不但继承了以上提到的Model S的各种问题(触摸屏,门把,……),而且还制造了新的问题.Model X具有一个 ...
- MyEclipse或Eclipse中project的导入和导出
project的导入:将project放到对应的目录中--打开MyEclipse--光标定位在PackageExp位置(即project创建位置),右键选中并点击"Import-" ...
- Struts2之数据标签(二)
Struts2之数据标签(一):http://blog.csdn.net/u012561176/article/details/46848817 1.action标签:使用此标签能够同意在JSP页面中 ...