[英]Selecting row with the highest column value among rows with the same value of another column
This time, I will ask about something works generally, but when data is huge it fails. 这次,我会问一些一般可行的方法,但是当数据量巨大时,它就会失败。
My case is the same in this post. 我的情况在这篇文章中是一样的。
how to query for rows that highest column value among rows that have same value for one of the columns 如何在其中一列具有相同值的行中查询列值最高的行
I used 我用了
SELECT `ID`, `PDBID`, `Chain`, `UniProtID`, `PDBASequence`, `pI`, `experiment`, `resolution`
FROM protein p
WHERE `resolution`= (SELECT MAX(`resolution`)
FROM protein
GROUP BY `PDBASequence`
HAVING `PDBASequence` = p.`PDBASequence`)
I also tried: 我也尝试过:
SELECT `ID`, `PDBID`, `Chain`, `UniProtID`, `PDBASequence`, `pI`, `experiment`, `resolution`
FROM protein p
WHERE `resolution`= (SELECT MAX(`resolution`)
FROM protein
WHERE `PDBASequence` = p.`PDBASequence`)
I have to group by sequences according to PDBASequence. 我必须根据PDBASequence按序列分组。 But, at the same time selected representative must be the one which has the max resolution value.
但是,同时选定的代表必须是具有最大分辨率值的代表。
I tried this code on a small set. 我尝试了一小段代码。 Working no problem.
工作没问题。 However, when I tried to run it on real table which has 80980 rows, execution takes almost forever.
但是,当我尝试在具有80980行的真实表上运行它时,执行几乎要花很多时间。 In addition, my other computer gives Mysql server has gone away error because of the execution type and pocket size.
另外,我的另一台计算机使Mysql服务器由于执行类型和存储袋大小而消失了错误。 I fixed the settings in my.ini and ran the code again.
我修复了my.ini中的设置,然后再次运行了代码。 Nothing changed.
没有改变。 Still no result :( What should I do? Thanks I assigned index on resolution in protein table. However,it did not change anything.
仍然没有结果:(我该怎么办?谢谢我在蛋白质表中为分辨率分配了索引。但是,它没有任何改变。
See if this version is any better. 看看这个版本是否更好。
SELECT p.`ID`, p.`PDBID`, p.`Chain`, p.`UniProtID`, p.`PDBASequence`, p.`pI`, p.`experiment`, p.`resolution`
FROM protein p
INNER JOIN (SELECT PDBASequence, MAX(`resolution`) AS MaxResolution
FROM protein
GROUP BY `PDBASequence`) q
ON p.PDBASequence = q.PDBASequence
AND p.resolution = q.MaxResolution
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.