我有四个相同的脚本,只有一个值在它们之间变化,我希望将它们组合成一个带有四个多输出的脚本。原因是BI Publisher不会在多个脚本之间渲染多个x轴日期,因此我尝试将其渲染为一个脚本。以下是所有四个脚本的相同脚本:
select to_char("DATA_POINT_DAILY_AVG"."DATE_OF_AVG", 'DD-MON-YY') as "DATE_OF_AVG",
"DATA_POINT_DAILY_AVG"."VALUE" as "DAILY_AVG_VALUE"
from "TEST"."COMPONENT" "COMPONENT",
"TEST"."COMPONENT_DATA_POINT" "COMPONENT_DATA_POINT",
"TEST"."DATA_POINT_DAILY_AVG" "DATA_POINT_DAILY_AVG"
where "COMPONENT"."SITE_ID" = ('123abc')
and "COMPONENT_DATA_POINT"."COMPONENT_ID"="COMPONENT"."ID"
and "COMPONENT_DATA_POINT"."NAME"='TEST_1'
and "DATA_POINT_DAILY_AVG"."COMPONENT_DATA_POINT_ID" = "COMPONENT_DATA_POINT"."ID"
and "DATA_POINT_DAILY_AVG"."SITE_ID" = "COMPONENT"."SITE_ID"
and "DATA_POINT_DAILY_AVG"."DATE_OF_AVG" between ('01-FEB-17') and ('28-FEB-17')
order by "DATA_POINT_DAILY_AVG"."DATE_OF_AVG" desc;
四个脚本之间唯一不同的行是:
and "COMPONENT_DATA_POINT"."NAME"='TEST_1'
对于所有四个(即,)来说如下:
and "COMPONENT_DATA_POINT"."NAME"='TEST_1'
and "COMPONENT_DATA_POINT"."NAME"='TEST_2'
and "COMPONENT_DATA_POINT"."NAME"='TEST_3'
and "COMPONENT_DATA_POINT"."NAME"='TEST_4'
其他一切都是相同的...预期输出将是:
DATE_OF_AVG DAILY_AVG_VALUE_1 DAILY_AVG_VALUE_2 DAILY_AVG_VALUE_3 DAILY_AVG_VALUE_4
----------- ----------------- ----------------- ----------------- -----------------
06-FEB-17 0 0 0 0
05-FEB-17 0 0 0 0
04-FEB-17 0 0 0 0
03-FEB-17 0 0 0 0
02-FEB-17 0 0 0 0
01-FEB-17 0 0 0 0
一个日期列,根据各种“TEST_x”值有四个不同的值。
我希望这是有道理的,任何帮助都会非常感激。谢谢!
答案 0 :(得分:0)
尝试此查询:
INSERT ON DUPLICATE KEY UPDATE
它会产生这样的结果:
select "COMPONENT_DATA_POINT"."NAME",
to_char("DATA_POINT_DAILY_AVG"."DATE_OF_AVG", 'DD-MON-YY') as "DATE_OF_AVG",
"DATA_POINT_DAILY_AVG"."VALUE" as "DAILY_AVG_VALUE"
from "TEST"."COMPONENT" "COMPONENT",
"TEST"."COMPONENT_DATA_POINT" "COMPONENT_DATA_POINT",
"TEST"."DATA_POINT_DAILY_AVG" "DATA_POINT_DAILY_AVG"
where "COMPONENT"."SITE_ID" = ('123abc')
and "COMPONENT_DATA_POINT"."COMPONENT_ID"="COMPONENT"."ID"
and "COMPONENT_DATA_POINT"."NAME" IN ('TEST_1','TEST_2','TEST_3','TEST_4')
and "DATA_POINT_DAILY_AVG"."COMPONENT_DATA_POINT_ID" = "COMPONENT_DATA_POINT"."ID"
and "DATA_POINT_DAILY_AVG"."SITE_ID" = "COMPONENT"."SITE_ID"
and "DATA_POINT_DAILY_AVG"."DATE_OF_AVG" between ('01-FEB-17') and ('28-FEB-17')
order by "COMPONENT_DATA_POINT"."NAME",
"DATA_POINT_DAILY_AVG"."DATE_OF_AVG" desc;