0

我有一个表(user_admin_password)。我正在使用此查询来获取记录。

SELECT user_key,admin_status,count(*) 
FROM user_admin_status 
GROUP BY 
   user_key,admin_status having count(*) > 1 
ORDER BY user_key,admin_status;

结果是:

+----------+--------------+----------+
| user_key | admin_status | count(*) |
+----------+--------------+----------+
|        1 | NON-DBA      |        5 |
|        3 | DBA          |      328 |
|        5 | NON-DBA      |        8 |
|        6 | NON-DBA      |       25 |
|        7 | NON-DBA      |        4 |
|        9 | DBA          |      232 |
|       10 | NON-DBA      |        4 |
|       11 | DBA          |        4 |
|       13 | NON-DBA      |        8 |
|       15 | NON-DBA      |        2 |
|       16 | DBA          |      326 |
|       16 | NON-DBA      |        2 |
|       17 | NON-DBA      |       10 |
|       18 | NON-DBA      |        5 |
|       19 | NON-DBA      |       12 |
|       20 | NON-DBA      |        2 |
|       21 | NON-DBA      |        2 |
...
...

现在,我想要所有具有重复记录的 user_keys...例如16...任何建议???

4

1 回答 1

3

只需将其包装在另一个选择中:

select user_key, count(*) 
from
(
    select user_key,admin_status,count(*) 
    from user_admin_status 
    group by user_key,admin_status 
    having count(*) > 1 
) x
group by user_key
having count(*) > 1 
于 2012-09-10T19:11:31.417 回答