我的这条查询语句有什么问题吗?为什么一运行,机器就卡死了!N久查询不出结果呀!求高手指点呀!
记录数并不多呀!也就1W多条呀!select imageid,path,keywords,viewcount,filename,created from images where imageid in(select max(imageid) FROM images group by keywords ) and categoryid<=4   order by viewcount desc  LIMIT 10
实在想不出是什么原因!

解决方案 »

  1.   

    select imageid,path,keywords,viewcount,filename,created
    from images A
    where categoryid<=4 and not exists (select 1 from images B where A.keywords=B.keywords and A.imageid<B.imageid)
    order by viewcount desc 
    LIMIT 10
      

  2.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  3.   

    select imageid,path,keywords,viewcount,filename,created from images a 
    inner join (select max(imageid) as ma FROM images group by keywords ) b
    on a.imageid=b.ma and categoryid<=4
     order by viewcount desc LIMIT 10
      

  4.   

    in右边的查询语句返回的记录越多越占CPU和内存,改用join会提高效率