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 ...
随机推荐
- GO语言中的几个关键思想
GO语言的设计理念与C++,Java,Python之流大相径庭. 一.没有函数重载 GO语言里面没有函数重载,Java.C#.C++三位大牛都是支持函数重载的,Python虽然不支持函数重载,但是支持 ...
- iOS 设备屏幕上实时打印 Log 的小工具
需求 写这个小工具的想法,主要来源于很多团队都会用友盟.TalkingData 等第三方框架做自定义事件统计:不过统计代码加好之后,没有很好的方法来让测试工程师验证一下事件加上了没有,调用次数有没有重 ...
- ajax提交出现的问题记载
1.普通ajax提交的时候是没法提交input type=file的,换句话说$_FILES获取不到ajax提交过去的值. 2.ajax提交的时候,设置dataType="json" ...
- 【Oracle】Oracle的内外连接
目录结构: contents structure [+] Oracle的内外连接 内连接 等值连接 非等值连接 自连接 外连接 外连接的特点 如何实现外连接 SQL99的内外连接 SQL99的内连接 ...
- 巧用linux服务器的/dev/shm/
巧用linux服务器的/dev/shm/,如果合理使用,可以避开磁盘IO不给力,提高网站访问速度. 首先让我们认识一下,什么是tmpfs和/dev/shm/? tmpfs是Linux/Unix系统上的 ...
- C++项目參考解答:求Fibonacci数列
[项目:求Fibonacci数列] Fibonacci数列在计算科学.经济学等领域中广泛使用,其特点是:第一.二个数是1,从第3个数開始,每一个数是其前两个数之和.据此,这个数列为:1 1 2 3 5 ...
- SharePoint 2013创建WCF REST Service
SharePoint 2013为开发者提供了丰富的REST API,方便了我们在客户端操作List中的数据.当然我们也可以在SharePoint 2013中创建自定义的REST Service,比如通 ...
- [转]Greenplum 通过gpfdist + EXTERNAL TABLE 并行导入数据
摘要: Greenplum 提供了快速导入数据的方法,下面通过一个例子演示给大家. Greenplum 提供了快速导入数据的方法,下面通过一个例子演示给大家. 我们用TPCH测试中最大的表做导入测试 ...
- mysql 多个字段 order by
mysql中,我们可以使用 ASC 或 DESC 关键字来设置查询结果是按升序或降序排列. 默认情况下,它是按升序排列. order by 后可加2个字段,用英文逗号隔开, 如A用升序, B降序,SQ ...
- django -- verbose_name的对数据库层面的影响
一.没有verbose_name时model的定义: from django.db import models # Create your models here. class Question(mo ...