我有类似的东西(日期简化为整数只是为了示例):
Order Date Value
12 5 555
12 5 800
12 2 900
13 3 122
13 4 155
14 1 121
... ... ...
我希望获得最高日期和最高价值的订单:
Order Date Value
12 5 800
13 4 155
14 1 121
... ... ...
我知道这与其他几个问题类似,但无法弄清楚如何将这些答案应用于我的案例,抱歉。
谢谢!
答案 0 :(得分:2)
使用分析函数ROW_NUMBER
items
答案 1 :(得分:2)
您可以使用分析FIRST / LAST功能(请参阅Oracle文档)。此解决方案不需要子查询/外部查询排列。我更改了列名,因为至少ORDER和DATE是Oracle关键字。
with
inputs ( ord, dt, val ) as (
select 12, 5, 555 from dual union all
select 12, 5, 800 from dual union all
select 12, 2, 900 from dual union all
select 13, 3, 122 from dual union all
select 13, 4, 155 from dual union all
select 14, 1, 121 from dual
)
-- End of test data (not part of the solution).
-- SQL query begins BELOW THIS LINE
select ord, max(dt) as dt, max(val) keep (dense_rank last order by dt) as val
from inputs
group by ord
;
ORD DT VAL
--- -- ---
12 5 800
13 4 155
14 1 121
答案 2 :(得分:0)
假设您的表名为orders
在子查询中,您会发现orders
dates
最高values
,而 select order,date,max(value) value from orders
where (order,date) in
(select order, max(date) date
from orders
group by order
)
group by order,date
order by order,date desc
找到最高<my-directive data-value="myController.somePropertyOnAController"><my-d...>
......看起来像这样:
<my-directive data-value="myController.getSomePropertyOnAController()"><my-d...>