I have four identical scripts that only have one value that varies between them that I would like to combine into one script with four multiple outputs. The reason for this is BI Publisher will not render multiple x-axis dates between multiple scripts, so I trying to make it so it renders as one script. The following is the same script for all four:
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;
the only line that varies between the four scripts is:
and "COMPONENT_DATA_POINT"."NAME"='TEST_1'
which would be as follows for all four (i.e.,):
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'
Everything else is identical...expected output would be:
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
One date column, with four different values based on the various "TEST_x" values.
I hope this makes sense, and any help would be greatly appreciated. Thanks!
Try this query:
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;
it will produce a result like this:
NAME DATE_OF_AVG DAILY_AVG_VALUE_1 DAILY_AVG_VALUE_2 DAILY_AVG_VALUE_3 DAILY_AVG_VALUE_4
---- ----------- ----------------- ----------------- ----------------- -----------------
TEST1 06-FEB-17 0 0 0 0
TEST1 05-FEB-17 0 0 0 0
....
....
TEST2 06-FEB-17 0 0 0 0
TEST2 05-FEB-17 0 0 0 0
....
....
TEST3 06-FEB-17 0 0 0 0
TEST3 05-FEB-17 0 0 0 0
....
....