delete from `mytable` where  typeid=4   order by id desc   limit 100,9999
如题 但我这样写不对。

解决方案 »

  1.   

    delete from mytable where mytable.id not in 
    (select id from (SELECT mytable.id from mytable where typeid=4   order by id desc limit 100) c)
      

  2.   

    借着在问
    -------------
    2个表
    tableA
    tableb
    其中b的id 与 A的id 值相同。
    根据 tableA中的 type 分组、统计记录合。找到大于100条记录的type保留每个大于100条type  的最新100条记录。其他的全部删除 同时删除,tableB中相对应的记录请问怎么写?表Aid               type
    1                1
    2                1
    3                2
    4                5
    .                .
    .                .
    .                .
    100              17
    101              16
    .                 .
    9999             52
    .
    .
    .
    99999            17
    表B(表BID 肯定与表A ID相同)
    ID               name
    1                a
    2                a
    3                v
    4                b
    .                .
    .                .
    .                .
    100              x
    101              v
    .                .
    9999             7
    .
    .
    .
    99999            5g
    -------------------------------------------现在希望把表A 按照type 分类。 并且统计记录和。   -select type, count(typeid) as tn from `tableA`  group by typeid order by nnn
    ---------------------------
    然后找到大于100条记录的 type   并且保留每个满足条件type的最新100条记录。其他的删除。
    删除的时候 顺便把B表中的 相关ID号的记录也删除了。
    不知道这样说能不能看懂  谢谢