一个关联表更新和性能问题

igyhi 2009-12-01 03:08:18
table
uid id name age
1 1 kaka 34
2 1 lala 38

table2
id worktime
1 2010-02-08 12:22:31
2 2008-06-26 05:14:48



由table2的worktime时间判断,如果worktime的时间晚于当前时间now(),则根据table的uid来把table表的age加1
已知table的uid 进行更新操作,比如

update table set age=age+1 where uid=1 and (由uid关联到本表id,在关联到tabel2的worktime,判断是不是大于now(),比当前时间晚,就更新)




这个操作是分成两步的,因为对sql不是很熟悉,如果我分成两部分来操作,性能降低的不会太多把
(已知table的uid和id)
比如先判断 table2 的时间是不是晚于now(); select id from table2 where id=1 and worktime>now();
晚于的话,然后在操作下 update table set age=age+1 where uid=1
...全文
44 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2009-12-01
  • 打赏
  • 举报
回复
update table inner join table2 on table.uid=table2.id
set age=age+1
where table2.worktime>now() and table2id=1
WWWWA 2009-12-01
  • 打赏
  • 举报
回复
update table a,table2 b
set a.age=a.age+1
where a.uid=b.id and b.worktime>now() and b.id=1
igyhi 2009-12-01
  • 打赏
  • 举报
回复
还有哪个一次性操作的update怎么写?

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧