假设有自增id
select *
from article A
where 6>(select count(*) from article B where A.category_id=B.category_id and A.id<B.id) and `category_id`
IN (
'101', '110'
)

解决方案 »

  1.   

    表里,有自增ID但COPY到SQL运行出错
    #1054 - Unknown column 'article.inputtime' in 'order clause'
      

  2.   

    SELECT *
    FROM `article`
    WHERE `category_id`
    IN = '101'
    LIMIT 0 , 30  
    union all
    SELECT *
    FROM `article`
    WHERE `category_id`
    IN = '110'
    LIMIT 0 , 30 
      

  3.   

    版主 将你的代码运行,出以下错误
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '101' LIMIT 0 , 30 union all SELECT * FROM `article` WHERE `category_id' at line 4麻烦你在我看看是那里的问题
      

  4.   

    (SELECT *
    FROM `article`
    WHERE `category_id`
    IN = '101'
    LIMIT 0 , 30  )
    union all
    (SELECT *
    FROM `article`
    WHERE `category_id`
    IN = '110'
    LIMIT 0 , 30 )加上括号试试
      

  5.   

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '101' LIMIT 0 , 30 ) union all (SELECT * FROM `article` WHERE `category_' at line 4还是报错! 不过谢谢版主!我有最笨的方法,一条一条写,效率上不来啊,只能先用
      

  6.   

    category_id`
    IN = '101'  后面有很多,不同的值,所以这种效率还能不能提高呢?