我想加入两个表,并在第一个表中插入新的计算数据,看一下示例:
表1:
Measure Value Date
Units 1.00 1
Dollar 25.00 1
Units 1.00 2
Dollar 25.00 2
表2:
Date Rate
1 1.05
2 1.09
我想在表1中加入,这一行意味着(美元:价值*同一日期的汇率)
Measure Value Date
LocalValue 26,25 1
LocalValue 27,25 2
我试着这样做,但我仍然有问题:
JOIN (Table2)
LOAD
'LocalValue' as [Measure],
[Value]*[Rate] AS [Value]
RESIDENT Table1
WHERE [Measure] = 'Dollar'
但我正在发送此错误消息: 找不到错误字段 -
我做错了什么?
此处示例:
Table1:
Load * inline
[
Measure,Value,Date
Units,1,1
Dollar,25,1
Units,1,2
Dollar,25,2
];
Table2:
Load * inline
[
Date,Rate
1,2
2,3
];
Table1:
JOIN (Table2)
LOAD
'LocalValue' as [Measure],
[Value]*[Rate] AS [Value]
RESIDENT Table1
WHERE [Measure] = 'Dollar'
答案 0 :(得分:1)
当您尝试“join(Table2)”字段时,Rate和Value不存在于您尝试加载的同一个表中(表1)。
在加入LocalValue计算之前,您需要在一个表中包含字段Value和Rate。 您的脚本需要如下所示:
Table1:
Load * inline
[
Measure,Value,Date
Units,1,1
Dollar,25,1
Units,1,2
Dollar,25,2
];
join
Table2:
Load * inline [
Date,Rate
1,2
2,3
];
JOIN (Table1)
//Table1:
LOAD
'LocalValue' as [Measure],
[Value]*[Rate] AS [Value]
RESIDENT Table1
WHERE [Measure] = 'Dollar'
结果表将是:
Measure Value Date Rate
Dollar 25 1 2
Units 1 1 2
Dollar 25 2 3
Units 1 2 3
LocalValue 50 - -
LocalValue 75 - -
的Stefan