1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来

MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来

时间:2023-05-06 01:44:36

相关推荐

MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来

项目中,评论数,关注数等数据,是实时更新的。+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语句总结

/article/32648.htm

2.如何将select出来的部分数据update到另一个表里面?

/topics/33666

MySql update inner join!MySql跨表更新 多表update sql语句?如何将select出来的部分数据update到另一个表里面?...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。