MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来的部分数据update到另一个表里面?
来源:互联网 发布:广州房地产交易数据 编辑:程序博客网 时间:2024/05/16 15:09
项目中,评论数,关注数等数据,是实时更新的。+1,-1 这种。
有的时候,可能统计不准确。
需要写一个统计工具,更新校准下。
用Java写SQL和函数,代码很清晰,方便扩展,但是太慢了。
为了简单起见,只写sql来统计,然后更新。(不想写存储过程)
语句如下:
#更新一个人的 关注数 followingCount
update behavior_redman_count ainner join(select memberId,count(*) as followingCount from behavior_follow where type = 10and isDelete=0 group by memberId )b set a.followingCount =b.followingCountwhere a.redmanId = b.memberId;
#MySQL不支持这种语法
update behavior_redman_countset followingCount = b.followingCountfrom(select count(*) as followingCount from behavior_follow where type = 10 and memberId = 198and isDelete=0)b where redmandId = a.memberId and a.memberId= 198;
参考资料
1. Mysql跨表更新 多表update sql语句总结
http://www.jb51.net/article/32648.htm
2.如何将select出来的部分数据update到另一个表里面?
http://bbs.csdn.net/topics/320233666
0 0
- MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来的部分数据update到另一个表里面?
- MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来的部分数据update到另一个表里面?
- 如何将select出来的部分数据update到另一个表对应的列里面?
- MYSQL update多条Select出来的数据 SQL写法
- Mysql跨表更新 多表update sql语句总结
- Mysql跨表更新 多表update sql语句总结
- mysql 将一个表里面的数据更新到另一个表里面
- mysql update select 语句
- mysql 多表update更新语句
- mysql update join sql语句总结
- Mysql跨表更新多表update sql语句
- Mysql多表update sql语句
- mysql:sql update语句
- mysql 更新数据 update
- 如何在一个update语句中,用一个表的数据更新另一个表的数据
- MySQL update && select ,update的同时select,和for update 语句说再见。
- sql update 多表关联 inner join
- MySQL Update inner join数据库去重,以及根据一张表的值更新另一张表
- js格式化日期
- 湖南省大学生计算机程序设计竞赛(残缺的棋盘)
- db2-event monitor
- 虚拟机sandbox启动不起来的原因
- 网易_在数组中查找前K个元素
- MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来的部分数据update到另一个表里面?
- C++ hdoj 2018 母牛的故事
- 汇总先
- 设计模式-装饰模式
- KMP详解
- 异常解析
- 自定义actionbar的xml(待补充)
- 基于Spring+SpringMVC+Mybatis的秒杀系统之web层(3)
- hdu-4734-数位Dp