FoxPro 6.0 - 在Select查询中添加行

时间:2017-06-14 13:16:10

标签: sql visual-foxpro foxpro

我在dbf文件中有一行代表每月一行,其中几个月从-250到+600。每行中都有一个名为t_from的变量代表月份。我想在几个月-150到0之间添加行。我该怎么做?是否可以在Select语句中执行此操作,还是需要更多其他内容?我已经通过'group by'语句中的一些变量进行分组。

示例数据,简化为仅显示一个分组变量:

Bus_LINE    t_from
--------    -------
ABC         -250
ABC         -249
ABC         ...
ABC         +599
ABC         +600
ZXC         -250
ZXC         -249
ZXC         ...
ZXC         +599
ZXC         +600
...
etc

1 个答案:

答案 0 :(得分:0)

    **** Assign variables to the input files ****
moses_output_file = output_path + "\CORP_DECEMBER2016~main9~CORP_REPORT.dbf"
SELECT 0
Use (moses_output_file) ALIAS cube_output1

**** Split the group string, only take values between months -150 and 0 ****
SELECT  2 AS t_month, padr(strextract(group,"|","|",4,1),10) AS reinsurance_book, padr(strextract(group,"|","|",5,1),10) AS Scheme, SUM(ms_fix_pay) AS mortswap_fixedleg_payment, SUM(premium_re) AS prem_reins, SUM(fixleg_res) AS quasi_fix_leg_reserve, SUM(fl_res_int) AS quasi_fix_leg_reserve_int, SUM(rfee_if) AS reinsfee_if, SUM(re_ben_res) AS reins_ben_res_if;
    FROM cube_output1;
        WHERE t_from >= -150 AND t_from <= 0;
    INTO CURSOR temp1 READWRITE;
    group by t_month, reinsurance_book, Scheme;

**** Split the group string, only take values for months 0 and 1 ****
SELECT  t_from AS t_month, padr(strextract(group,"|","|",4,1),10) AS reinsurance_book, padr(strextract(group,"|","|",5,1),10) AS Scheme, SUM(ms_fix_pay) AS mortswap_fixedleg_payment, SUM(premium_re) AS prem_reins, SUM(fixleg_res) AS quasi_fix_leg_reserve, SUM(fl_res_int) AS quasi_fix_leg_reserve_int, SUM(rfee_if) AS reinsfee_if, SUM(re_ben_res) AS reins_ben_res_if;
    FROM cube_output1;
        WHERE t_from = 0 OR t_from = 1;
    INTO CURSOR temp2 READWRITE;
    group by t_month, reinsurance_book, Scheme;

SELECT * FROM temp1;
     UNION;
SELECT * FROM temp2;
     INTO CURSOR temp3 READWRITE;