将相同的 Oracle SQL 脚本合并为一个?
Combining Same Oracle SQL Scripts in One?
我有四个相同的脚本,它们之间只有一个值不同,我想将它们组合成一个具有四个多输出的脚本。这样做的原因是 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" 值的四个不同值。
我希望这是有道理的,我们将不胜感激。谢谢!
试试这个查询:
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;
它会产生这样的结果:
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
....
....
我有四个相同的脚本,它们之间只有一个值不同,我想将它们组合成一个具有四个多输出的脚本。这样做的原因是 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" 值的四个不同值。
我希望这是有道理的,我们将不胜感激。谢谢!
试试这个查询:
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;
它会产生这样的结果:
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
....
....