获取MySQL中具有最高值的行 [英] get the row with the highest value in MySQL

查看:64
本文介绍了获取MySQL中具有最高值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得最大值,但按同一表上的另一个字段分组 例如:

I want to get the highest value but group by another field on the same table ex:

seqid + fileid + name

seqid + fileid + name

1  |    1 | n1
2  |    1 | n2
3  |    2 | n3
4  |    3 | n4
5  |    3 | n5

结果必须是

seqid + fileid + name

seqid + fileid + name

2  |    1 | n2
3  |    2 | n3
5  |    3 | n5

注意:所有字段必须像使用select *一样显示 我将不胜感激.tnx

note: all the field must be display like using select * I'll appreciate any help.tnx

推荐答案

类似的东西

SELECT  t.*
FROM    Table t INNER JOIN
        (
            SELECT  fileid,
                    MAX(seqid) Maxseqid
            FROM    Table
            GROUP BY    fileid
        ) m ON  t.fileid = m.fileid
            AND t.seqid = m.Maxseqid

这篇关于获取MySQL中具有最高值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆