有表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.   

    update cdb_zt_aats_cooperation set ztname = 'abcdefg' where id in (46,47,48) order by id desc limit 2
    可以啊
      

  2.   

    恩,不是这个意思,我是要修改每个typeid的前8条记录
      

  3.   

    哦UPDATE `archives` SET `senddate` = UNIX_TIMESTAMP( ) WHERE typeid in (select distinct(typeid) from archives) order by senddate asc limit 8
      

  4.   

    没弄出来,楼主还是distinct将typeid的出来,在update吧
    (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
      

  5.   

    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 test2.senddate=UNIX_TIMESTAMP() where archives.id = T.id
      

  6.   

    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 test2.senddate=UNIX_TIMESTAMP() where archives.id = T.id
      

  7.   

    晕,本地测试过的,老贴错。
    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
      

  8.   

    那我在哪写typeid >=207 and typeid <= 215 and typeid= 219呢
      

  9.   

    typeid >=207 and typeid <= 215 and typeid= 219
    ------------------------------------------------
    你再想想,这个条件逻辑能通吗?应该是 (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