选择表中每个最大值的id

时间:2016-02-16 09:23:19

标签: mysql

如何选择表格中每个最大值的id?

enter image description here

预期产出:

enter image description here

1 个答案:

答案 0 :(得分:1)

你可以这样做:

SELECT * FROM(
    SELECT distinct id as 1st
    FROM YourTable
    WHERE 1st =(select max(1st)
                FROM YourTable))
INNER JOIN
    (SELECT distinct id as 2nd
    FROM YourTable
    WHERE 2nd =(select max(2nd)
                FROM YourTable))
ON(1=1)  

这仅适用于每列中有1个MAX值的情况。

下次你提出问题时,请尝试自己解决问题。