开发者

Find max value in pl/sql where there are 2 values that are max

开发者 https://www.devze.com 2023-02-02 12:37 出处:网络
I am using oracle sql developer and I was wondering how you can query the max value of a column where the column has two values that are the max?

I am using oracle sql developer and I was wondering how you can query the max value of a column where the column has two values that are the max?

For example:

Shapes

square

square

square

triangle

circle

circle

circle

when i do select max(shapes), it only gives square but not circle even thou开发者_JAVA百科gh both is the max.


May not the best way, but u can try:

SELECT * 
FROM   (SELECT a.*, 
               Rank() OVER(PARTITION BY shapes ORDER BY sm DESC) rnk 
        FROM   (SELECT shapes, 
                       SUM(1) OVER(PARTITION BY shapes ORDER BY shapes) sm 
                FROM   shapes_table) a) 
WHERE  rnk = 1 


select Shapes from TableName
group by Shapes
having COUNT(*) = (
select top 1 COUNT(*) from TableName
group by Shapes order by Shapes desc)

This query will give all shapes repeating in that table for maximum times. (This is what I got from your question..)

0

精彩评论

暂无评论...
验证码 换一张
取 消