首页 > 解决方案 > 如何在 obiee 中显示一个月中所有日期的一个值?

问题描述

这可能看起来很奇怪,但我需要在一个月的所有日子里显示一个值。

在数据库中,只有月​​份第一天的记录。当我在带有日期提示的 BI 中创建分析时,显然除了一个月的第一天之外,我每天都会得到空值。我如何才能整天解决这个问题(01.01.2018、01.02.2018 等)?当然,当月份更改时,列应该显示下个月第一天的值。有没有办法做到这一点?

标签: oraclebusiness-intelligenceobiee

解决方案


这样的查询会有什么好处吗?

the_whole_monthCTE 创建每个月的所有天数;表函数调用是为了避免重复

SQL> with test (first_day, value) as
  2    (select date '2018-01-01', 100 from dual union all
  3     select date '2018-02-01', 200 from dual union all
  4     select date '2018-03-01', 300 from dual
  5    ),
  6  the_whole_month as
  7    (select (first_day + column_value - 1) datum, value
  8     from test,
  9          table(cast(multiset(select level from dual
 10                              connect by level <= last_day(first_day) - first_day + 1
 11                             ) as sys.odcinumberlist))
 12    )
 13  select * from the_whole_month
 14  order by datum;

DATUM         VALUE
-------- ----------
01.01.18        100         -- January begins here
02.01.18        100
<snip>
29.01.18        100
30.01.18        100
31.01.18        100
01.02.18        200         -- February begins here
02.02.18        200
<snip>
27.02.18        200
28.02.18        200
01.03.18        300         -- March begins here
02.03.18        300
<snip>
29.03.18        300
30.03.18        300
31.03.18        300

90 rows selected.

SQL>

关于重复项(你会得到没有表功能):查询看起来像这样;我把这几个月缩短到每个只有 3 天。您预计 3 monts x 3 天 = 9 行,但您将获得 39 行。如果您有足够的耐心运行它整个月,并且在您拥有的所有月份中,您可能会得到......我不知道,数百万行。不要那样做。

SQL> with test (first_day, value) as
  2    (select date '2018-01-01', 100 from dual union all
  3     select date '2018-02-01', 200 from dual union all
  4     select date '2018-03-01', 300 from dual
  5    ),
  6  the_whole_month as
  7    (select (first_day + level - 1) datum, value
  8     from test
  9     connect by level <= 3  --> Presuming there are only 3 days in every month.
 10                            --> You'd expect 3 x 3 = 9 rows, but you'll get 39.
 11    )
 12  select * from the_whole_month
 13  order by datum;

DATUM         VALUE
-------- ----------
01.01.18        100
02.01.18        100
02.01.18        100
02.01.18        100
03.01.18        100
03.01.18        100
03.01.18        100
<snip>  
03.03.18        300
03.03.18        300

39 rows selected.

SQL>

推荐阅读