Heim >Backend-Entwicklung >PHP-Tutorial > mysql 查寻重复姓名且年龄最大的列表
mysql 查找重复姓名且年龄最大的列表
<br /> mysql> select count(*) as count ,name,sum(age) as age from t1 group by name order by count desc;<br /> +-------+--------+------+<br /> | count | name | age |<br /> +-------+--------+------+<br /> | 3 | atest | 64 |<br /> | 2 | btest | 37 |<br /> | 2 | ctest | 43 |<br /> | 2 | dtest | 43 |<br /> | 1 | mary | 22 |<br /> | 1 | kou | 22 |<br /> | 1 | perter | 23 |<br /> | 1 | kate | 19 |<br /> +-------+--------+------+<br /> 8 rows in set (0.00 sec)<br />
<br /> mysql> select count,name,age from ( select count(*) as count ,name,sum(age) as age from t1 group by<br /> name order by count desc ,age desc ) as tmp group by count order by count desc ,age desc;<br /> +-------+--------+------+<br /> | count | name | age |<br /> +-------+--------+------+<br /> | 3 | atest | 64 |<br /> | 2 | ctest | 43 |<br /> | 1 | perter | 23 |<br /> +-------+--------+------+<br /> 3 rows in set (0.00 sec)<br />