1

我有一个包含三个字段的表user_namepage并且n_loads。我想按 对表格进行分组user_name,对于每个用户名,我想显示最大负载数以及与此(最大)负载数相对应的页面。我可以在一个 MySQL 子句中做到这一点吗?

4

1 回答 1

3
SELECT  a.*
FROM    tableName a
        INNER JOIN
        (
            SELECT  username, MAX(n_loads) n_loads
            FROM    tableName 
            GROUP   BY username
        ) b ON  a.username = b.username AND
                a.n_loads = b.n_loads

或者

SELECT  a.*
FROM    tableName a
WHERE   n_loads = 
        (SELECT MAX(b.n_loads)
        FROM    tableName b
        WHERE   a.username = b.username);
于 2013-06-25T04:38:42.950 回答