mysql 查寻重复姓名且年龄最大的列表

WBOY
Release: 2016-06-13 12:43:59
Original
926 people have browsed it

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 />
Copy after login

这里找到count 重复的数据
下面接着找 count 最大,切age 最大且相同的数据
<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 />
Copy after login

为什么少了一条  dtest   ,dtest的数据和ctest在count和age上是一样的?

求指教!谢谢

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template