select x
from table1
group by x
having count(*)<=5

解决方案 »

  1.   

    错了是order bySELECT  * 
    FROM  `article` 
    WHERE cateid
    IN ( 7, 12  ) 
    having count(*)<=5
    order by cateid;一个结果也没有
      

  2.   

    CREATE TABLE `article` (
      `articleid` int(10) unsigned NOT NULL auto_increment,
      `cateid` int(10) NOT NULL default '0',
      `posttime` int(10) unsigned NOT NULL default '0',
      `author` varchar(50) NOT NULL default '',
      `title` varchar(100) NOT NULL default '',
      `description` text,
      `clicktimes` int(10) unsigned NOT NULL default '0',
      `rating` int(2) NOT NULL default '0',
      `votes` smallint(6) NOT NULL default '0',
      `ipaddress` varchar(16) NOT NULL default '',
      `commentnum` smallint(8) NOT NULL default '0',
      `published` enum('y','n') NOT NULL default 'n',
      PRIMARY KEY  (`articleid`),
      KEY `postid` (`articleid`),
      KEY `published` (`published`)

      

  3.   

    select x as a from table1 group by x
    while
      SELECT  * FROM  `article` WHERE x=a order by cateid limit 5;
    用循环吧!一条语句实现不了。