【发布时间】:2021-06-27 16:05:27
【问题描述】:
【问题讨论】:
-
这能回答你的问题吗? Oracle SQL pivot query
【问题讨论】:
看起来像一个支点。
#1 - 10 行中的示例数据;您可能需要的查询从第 12 行开始。
SQL> with test (id_value, as_of, timezone, price, owner) as
2 -- sample data
3 (select 'EEM.A', date '2021-06-25', 'J1530', 55.04, 55 from dual union all
4 select 'EEM.A', date '2021-06-25', 'J1530', 55.04, 27 from dual union all
5 select 'EEM.A', date '2021-06-25', 'J1530', 55.04, 2 from dual union all
6 --
7 select 'AMX.N', date '2021-06-25', 'J1530', 15.4, 55 from dual union all
8 select 'AMX.N', date '2021-06-25', 'J1530', 15.4, 27 from dual union all
9 select 'AMX.N', date '2021-06-25', 'J1530', 15.4, 2 from dual
10 )
11 -- query begins here
12 select *
13 from test
14 pivot (max(price)
15 for owner in (55, 27, 2)
16 );
ID_VA AS_OF TIMEZ 55 27 2
----- ---------- ----- ---------- ---------- ----------
AMX.N 06/25/2021 J1530 15,4 15,4 15,4
EEM.A 06/25/2021 J1530 55,04 55,04 55,04
SQL>
【讨论】:
and asof = date '2021-06-25'