如何显示一个月中所有天的一个值?

时间:2018-09-27 10:40:53

标签: oracle business-intelligence obiee

这可能看起来很奇怪,但是我必须在一个月的所有天中显示一个值。

在数据库中,仅有几个月的第一天的记录。当我在带有日期提示的BI中创建分析时,很明显,除一个月的第一天外,每一天我都得到空值。我如何整天修复此measere(值在01.01.2018,01.02.2018等)?当然,当月份更改时,列应显示下个月第一天的值。 有办法吗?

2 个答案:

答案 0 :(得分:1)

这样的查询有好处吗?

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

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个月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>

答案 1 :(得分:1)

对于时间维度(月度级别),将聚合规则设置为FIRST,对于所有其他条件,将聚合规则设置为SUM。