0

以下是我的表格内容:

select * from summary_weekly_sales;

DISTRIBUTOR    DATE_OF_ACTIVATION  NUMBER_OF_SALES
-------------- ------------------  ---------------
charan          25-APR-13              23
charan          26-APR-13               2
charan          28-APR-13               5
charan          29-APR-13              50
anil            25-APR-13              13
anil            26-APR-13               4
anil            28-APR-13               5
anil            29-APR-13              30

在 ireport DATE_OF_ACTIVATION 是输入参数(但这里我将 date_of_activation 设为 29-APR-13),我希望输出显示如下:

DISTRIBUTOR    avg_sales_week   NUMBER_OF_SALES
-------------- ---------------  ---------------
charan          10              50

anil            7.33            30

在哪里,

avg_sales_week是每个分销商的平均周销售额(即 29-APR-13 前 7 天)

即对于charan分销商平均值 = (5+2+23)/3

Number_Of_Sales是 29-APR-13 完成的销售额

我尝试使用oracle 的wm_concat函数,但它没有按预期工作。

有什么办法可以得到上述预期的结果。

问候, 查兰

4

2 回答 2

2

这会做到:

select distributor
,      sum(case when date_of_activation < date '2013-04-29'
           then number_of_sales end)  
       / count(distinct case when date_of_activation < date '2013-04-29' 
           then date_of_activation end) as avg_sales_week   
,      sum(case when date_of_activation=date '2013-04-29' 
           then number_of_sales end) number_of_sales
from   summary_weekly_sales
where  date_of_activation between date '2013-04-29' - 7 and date '2013-04-29'
group by distributor;

DISTRIBUTO AVG_SALES_WEEK NUMBER_OF_SALES
---------- -------------- ---------------
anil           7.33333333              30
charan                 10              50

只需用date '2013-04-29'您的参数名称替换,例如p_date在过程中使用。

于 2013-05-02T13:20:30.473 回答
0
select 
distributor, 
sum(number_of_sales) / 
    (select count(*) from summary_weekly_sales sws2 where sws2.distributor = distributor and sws2.date_of_activation > '29-APR-13' - 7)
as avg_sales_week, 
number_of_sales
FROM summary_weekly_sales
WHERE DATE_OF_ACTIVATION > '29-APR-13' - 7
GROUP BY distributor

也许这应该有所帮助。

于 2013-05-02T13:03:16.100 回答