简体   繁体   English

在与另一列具有相同值的行中选择具有最高列值的行

[英]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.

相关问题 SQL中同一行的列值中第二高的值 - Second highest value among column values of same row in SQL 如何查询具有第v.2列之一相同值的行中具有最高列值的行 - How to query for rows that have highest column value among rows that have same value for one of the columns v.2 从列A中具有相同值的每组行中删除除B列中具有最高值的行之外的所有行 - From every set of rows with the same value in column A delete all rows but the row with the highest value in column B SQL选择除具有最高值的列之外的所有行 - SQL Selecting all rows except the column with the highest value 选择列值相同的行 - Selecting rows where column value is the same 根据列值选择另一行 - Selecting another row based on column value 返回一列具有最大值的行,而另一列具有给定值 - Return rows with the highest value on one column corresponding to a given value in another 将一列的值添加到同一ROW上的另一列 - Add the value of a column to another column on the same ROW SQL:删除重复行,同时保留另一列中具有最高值的行 - SQL: Removing Duplicates rows while retaining the row with highest value in another column MySQL:在不知道该列值的情况下选择1列相同的行? - MySQL: Selecting rows where 1 column is the same without knowing the value of that column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM