简体   繁体   English

选择具有最大条目数的值 - Oracle 数据库

[英]Select value with maximum number of entries - Oracle Database

This is what I have:这就是我所拥有的:

A table PATENT with a column ASSIGNEE .带有列ASSIGNEEPATENT I want to find the ASSIGNEE with maximum number of entries in the table.我想在表中找到具有最大条目数的ASSIGNEE

And this is what I am trying to do:这就是我想要做的:

SELECT ASSIGNEE
FROM (
    SELECT ASSIGNEE, count(*) num_assignee
    FROM PATENT
    GROUP BY ASSIGNEE
    ORDER BY num_assignee DESC
)
WHERE ROWNUM <= 1

This works great for only one maximum, however, in the case of a tie, the other ASSIGNEE is not shown.这仅适用于一个最大值,但是,在平局的情况下,不会显示另一个ASSIGNEE How to resolve this?如何解决这个问题?

You may try this:你可以试试这个:

SELECT assignee
FROM (
    SELECT assignee, 
           count(*) num_assignee,
           MAX(count(*)) OVER () max_num_assignee
    FROM patent
    GROUP BY assignee
    )
WHERE num_assignee = max_num_assignee;

Try this.尝试这个。

SELECT assignee 
FROM
(
    SELECT TOP 1 assignee, count(*) num_assignee
    FROM patent
    GROUP BY assignee
    ORDER BY num_assignee DESC
) Source

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM