你的位置:
问答吧
-> MySQL
-> 问题详情
一条MySQL查询语句,卡死机器,不知道为什么,求高手指点!
我的这条查询语句有什么问题吗?为什么一运行,机器就卡死了!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
实在想不出是什么原因!
作者: hya0502
发布时间: 2010-11-16
SQL code
selectimageid,path,keywords,viewcount,filename,createdfromimages Awherecategoryid<=4andnotexists(select1fromimages BwhereA.keywords=B.keywordsandA.imageid
作者: rucypli
发布时间: 2010-11-16
引用 1 楼 rucypli 的回复:
SQL code
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
order b……
可以说说,我那样写代码不好在哪不?好想知道呀!急死了!
作者: hya0502
发布时间: 2010-11-16
参考下贴中的多种方法
http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
[征集]分组取最大N条记录方法征集,及散分....
作者: ACMAIN_CHM
发布时间: 2010-11-16
尽量不要用子查询,分组及排序,没效率
作者: fxs_2008
发布时间: 2010-11-16
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
作者: wwwwb
发布时间: 2010-11-16
讨论了一条导致机器卡死的MySQL查询语句,记录数约1万条。通过社区讨论,提出了几种可能的优化方案,包括避免使用子查询、分组及排序。

被折叠的 条评论
为什么被折叠?



