有表archivesid senddate typeid
1 1月15日 207
2 1月16日 207
3 1月15日 207
……
4 1月15日 208
5 1月17日 208
……
6 1月18日 209
写了句sql,将archives表中我给定的typeid中时间升序8条改成当前时间(今天)。(实际表中时间是unix时间,这里写了概念时间。)UPDATE `archives` SET `senddate` = UNIX_TIMESTAMP( ) WHERE typeid =207 order by senddate asc limit 8现在想在这句sql里加什么,修改多个typeid的记录。比如typeid >=207 and typeid <= 215 and typeid= 219怎么写呢?我在网上查,好像sql语句中updata 和 in不能在同一个表中使用???谢谢各位老师~~
1 1月15日 207
2 1月16日 207
3 1月15日 207
……
4 1月15日 208
5 1月17日 208
……
6 1月18日 209
写了句sql,将archives表中我给定的typeid中时间升序8条改成当前时间(今天)。(实际表中时间是unix时间,这里写了概念时间。)UPDATE `archives` SET `senddate` = UNIX_TIMESTAMP( ) WHERE typeid =207 order by senddate asc limit 8现在想在这句sql里加什么,修改多个typeid的记录。比如typeid >=207 and typeid <= 215 and typeid= 219怎么写呢?我在网上查,好像sql语句中updata 和 in不能在同一个表中使用???谢谢各位老师~~
可以啊
(1)select GROUP_CONCAT(DISTINCT typeid) from archives得出结果$s(2)update archives set `senddate` = UNIX_TIMESTAMP() where typeid in ($s) order by id asc limit 2
8 >(select count(*) from `archives` where typeid=a.typeid and senddate < a.senddate)
order by a.senddate asc) T set test2.senddate=UNIX_TIMESTAMP() where archives.id = T.id
8 >(select count(*) from `archives` where typeid=a.typeid and senddate < a.senddate)
order by a.senddate asc) T set test2.senddate=UNIX_TIMESTAMP() where archives.id = T.id
update `archives` , (select senddate,typeid,id from `archives` a where
8 >(select count(*) from `archives` where typeid=a.typeid and senddate < a.senddate)
order by a.senddate asc) T set archives.senddate=UNIX_TIMESTAMP() where archives.id = T.id
------------------------------------------------
你再想想,这个条件逻辑能通吗?应该是 (typeid >=207 and typeid <= 215) OR typeid= 219 吧update `archives` , (select senddate,typeid,id from `archives` a where
8 >(select count(*) from `archives` where typeid=a.typeid and ((typeid >=207 and typeid <= 215) OR typeid= 219) and senddate < a.senddate)
order by a.senddate asc) T set archives.senddate=UNIX_TIMESTAMP() where archives.id = T.id