这导致每周总计。
SUM(GENERATED_FOR_WEEK(et.START_DATE, et.END_DATE, elm.element_id, MON...SUN_ )) OVER(PARTITION BY elm.element_id, et.START_DATE)as WEEK_HRS_TOTAL
我在这里选择了另一个与上面一个完全相同的求和函数,除了这个总和是总计年份的WEEK_HRS_TOTAL。因此导致每个条目的培养总计。但是在这个总和中我用elm.Name和子元素名称elm.SubName进行分区并返回为HRS_TOTAL_YEAR
SUM(GENERATED_FOR_YEAR(et.START_DATE,et.END_DATE,elm.element_id,MON ... SUN_))OVER(PARTITION BY elm.Name,elm.SubName)为HRS_TOTAL_YEAR
此结果符合预期,但问题是每个记录都会显示总数,需要将其显示为运行总计。
示例:
ELM NAME ELM SUB_NAME WEEK_HRS_TOTAL HRS_TOTAL_YEAR
DOOR KNOB 12 37
DOOR KNOB 23 37
DOOR KNOB 2 37
DOOR PAINT 3 10
DOOR PAINT 4 10
DOOR PAINT 3 10
我会尝试使用
DENSE_RANK根据elm.SubName给出
生成一列ELM NAME ELM SUB_NAME WEEK_HRS_TOTAL RANK HRS_TOTAL_YEAR
DOOR KNOB 12 1 37
DOOR KNOB 23 1 37
DOOR KNOB 2 1 37
DOOR PAINT 3 2 10
DOOR PAINT 4 2 10
DOOR PAINT 3 2 10
有没有办法让我的HRS_TOTAL_YEAR使用RANK列而不是ELM SUB_NAME来创建运行总计,从而产生以下结果?
ELM NAME ELM SUB_NAME WEEK_HRS_TOTAL RANK HRS_TOTAL_YEAR
DOOR KNOB 12 1 12
DOOR KNOB 23 1 35
DOOR KNOB 2 1 37
DOOR PAINT 3 2 3
DOOR PAINT 4 2 7
DOOR PAINT 3 2 10
Create or Replace "WEEK_HRS_TOTAL" (p_start_date et.start_date%type,
p_end_date et.end_date%type,
p_elm_id elm.element_id,
p_sun_hrs et.sun_hrs
.....this continues for each day of the week) Return Number AS
lv_dollar_gen_sum number;
lv_start_date date;
lv_end_date date;
lv_rate elm.rate%type;
begin
loop
exit when lv_start_date >= lv_end_date;
select r.rate into lv_rate
from hour_rate r
where r.element_id = p_element_id and
r.start_date <= lv_start_date and
r.end_date > lv_start_date;
lv_dollar_gen_sum := lv_dollar_gen_sum + (p_mon_hrs * lv_rate);
lv_start_date := lv_start_date + 1;
我们在一周中的每一天都这样做,然后返回结果。两个函数都做同样的事情,但是WEEKS_HRS_TOTAL函数调用的分区基于element_id和et.start_date
虽然HRS_TOTAL_YEAR的分区基于elm.Name,elm.SubName
答案 0 :(得分:0)
您只需向ORDER BY
添加SUM()
即可。但是,您的数据没有明显的列:
SUM(GENERATED_FOR_YEAR(et.START_DATE, et.END_DATE, elm.element_id, MON...SUN_ )) OVER
(PARTITION BY elm.Name, elm.SubName
ORDER BY ??
) as HRS_TOTAL_YEAR
您所显示的数据中没有任何内容符合您的要求。