2

我正在创建一个脚本,通过某些 ID 矩阵 ID 总结损益 (PL)。我对视图“vw_package”使用以下 SQL 语句:

select trade_matrix_id, sum(pl) from vw_package 
where date (gen_timestamp) between '2012-05-01' and '2012-05-30' 
and trade_matrix_id between 30 and 60
group by trade_matrix_id;

它正确地产生了这个结果:

trade_matrix_id,sum(pl)
41,            -147.33
42,             -27.45
43,            -329.03
44,            -329.03
45,            -329.03
...

现在我想用这些结果填写一张表格。我在脚本中创建了一个表:

CREATE TABLE IF NOT EXISTS PLByMatrixID 
    (trade_matrix_id    int,
    Sum_PL              float(19,2));

我使用 INSERT 命令使用与上面完全相同的 SELECT 语句填充表:

insert into PLByMatrixID (trade_matrix_id, Sum_PL)
   select trade_matrix_id, sum(pl) from vw_package 
   where date (gen_timestamp) between '2012-05-01' and '2012-05-30' 
   and trade_matrix_id between 30 and 60
   group by trade_matrix_id;

我调用脚本并查询结果 tablePLByMatrixID 并且 PL 中的所有值都是 NULL:

41,            NULL
42,            NULL
43,            NULL
...

如果有人能告诉我我在这里缺少什么,我将不胜感激。

4

1 回答 1

0

尝试

   select trade_matrix_id, sum(pl)
   into PLByMatrixID 
   from vw_package 
   where date (gen_timestamp) between '2012-05-01' and '2012-05-30' 
   and trade_matrix_id between 30 and 60
   group by trade_matrix_id;
于 2013-06-16T15:46:48.430 回答