这是我的数据样本
select * from (
select 'A' as POD, 164 as result from dual union all
select 'A' as POD, 3 as result from dual union all
select 'A' as POD, 2 as result from dual union all
select 'B' as POD, 409 as result from dual union all
select 'B' as POD, 128 as result from dual union all
select 'B' as POD, 5 as result from dual union all
select 'C' as POD, 12391 as result from dual union all
select 'C' as POD, 624 as result from dual union all
select 'C' as POD, 405 as result from dual union all
select 'C' as POD, 26 as result from dual union all
select 'C' as POD, 3 as result from dual union all
select 'C' as POD, 2 as result from dual
)
荚 | 结果 |
---|---|
一个 | 164 |
一个 | 3 |
一个 | 2 |
乙 | 409 |
乙 | 128 |
乙 | 5 |
碳 | 12391 |
碳 | 624 |
碳 | 405 |
碳 | 二十六 |
我想要的是按照首次计数最高的组对它们进行排序:
荚 | 结果 |
---|---|
碳 | 12391 |
碳 | 624 |
碳 | 405 |
碳 | 二十六 |
乙 | 409 |
乙 | 128 |
乙 | 5 |
一个 | 164 |
一个 | 3 |
一个 | 2 |
我甚至不知道如何用 SQL 来表达这个
C
result
在第一行中具有最高值,然后B
具有第二高值A
我理解这个任务如下:
现在,我们认为最高的结果是什么?这是每个 pod 的最大结果吗?那将是 A = 164,B = 409,C = 12391。我们可以用
或者它是每个 pod 的最大结果总和?那将是 A = 169,B = 542,C = 13446。我们需要的表达式是
在你的子句中使用其中一个
ORDER BY
。例如:另一种方法是使用 row_number 按以下方式对数据进行排序:
希望有帮助。