[英]how to use an Oracle query in Mapping of ODI 12c
I have a table like this:我有一张这样的桌子:
CREATE TABLE risk_test
(id VARCHAR2 (32) NOT NULL PRIMARY KEY,
customer_id varchar2 (40BYTE),
risk number,
day VARCHAR2(50 BYTE))
insert into risk_test values(1,102,15,1);
insert into risk_test values(2,102,16,1);
insert into risk_test values(3,104,11,1);
insert into risk_test values(4,102,17,2);
insert into risk_test values(5,102,10,2);
insert into risk_test values(6,102,13,3);
insert into risk_test values(7,104,14,2);
insert into risk_test values(8,104,13,2);
insert into risk_test values(9,104,17,1);
insert into risk_test values(10,104,16,2);
I want to calculate total risk and save result in new table.我想计算总风险并将结果保存在新表中。 So, I create a procedure in ODI and write this query in it:因此,我在 ODI 中创建了一个过程并在其中编写了以下查询:
create table risk_odi as
SELECT o.*,ROUND (
SUM (day_minus_day0 * risk) OVER (PARTITION BY customer_id)
/ SUM (day_minus_day0) OVER (PARTITION BY customer_id),
5) AS total_risk
FROM (SELECT rt.*, (rt.day - MIN (rt.day) OVER (PARTITION BY customer_id)) + 1 AS day_minus_day0
FROM risk_test rt) o
ORDER BY customer_id, TO_NUMBER (day), TO_NUMBER (id)
The result table is like this:结果表是这样的:
My question is that I want to create the table in mapping;我的问题是我想在映射中创建表; therefore, would you please guide me how I can run the above query in mapping, using Aggregate Component or Expression Component ?因此,请您指导我如何使用Aggregate Component或Expression Component在映射中运行上述查询?
Any help is really appreciated.非常感谢任何帮助。
Problem solved.问题解决了。 I use this structure in mapping:我在映射中使用这个结构:
First, I use a filter to extract the last thirty days and save it to the thirtyday table.首先,我使用过滤器提取最后三十天并将其保存到三十天表中。 After that, I use aggregate to group data based on customer_id and calculate the minimum day in each group.之后,我使用聚合根据customer_id对数据进行分组,并计算每个组中的最短天数。 Then joining aggregate result with thirtyday.然后将汇总结果与 30 天一起加入。 The last aggregate is for calculating total_risk based on grouping customer_id .最后一个聚合用于根据分组customer_id计算total_risk 。 Finally, I save data to the last table which is the result.最后,我将数据保存到最后一个表,这是结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.