我的报告规格总结如下:
--------+----------------------+----------------------+----------------------+------------+
| January | February | March | |
--------+----------------------+----------------------+----------------------+------------+
Dealer | Target | Actual | % | Target | Actual | % | Target | Actual | % | TOTAL |
--------+--------------------------------------------------------------------+------------+
P501 | 100 | 90 | 90 | 100 | 85 | 85 | 100 | 93 | 93 | 268 |
--------+--------------------------------------------------------------------+------------+
P502 | 100 | 89 | 89 | 100 | 88 | 88 | 100 | 92 | 92 | 269 |
--------+--------------------------------------------------------------------+------------+
a)要显示的月数作为参数传递。对于季度报告,将有3个月;半年一次将有6个月;对于年度,将显示所有12个月。
b)使用下面的SQL语句从数据库表中读取Region,Target和Actual数据:
select concat(d.dealer_code,"-",dealer_name) as dealer
,s.month
,case
when s.month="1" then "January"
when s.month="2" then "February"
when s.month="3" then "March"
when s.month="4" then "April"
when s.month="5" then "May"
when s.month="6" then "June"
when s.month="7" then "July"
when s.month="8" then "August"
when s.month="9" then "September"
when s.month="10" then "October"
when s.month="11" then "November"
else "December"
end as month_name
,case
when s.type = "PA" then "Actual"
else "Target"
end as type
,s.amount
from t_pbo_sales s, t_pbo_dealer d
where s.dealer_id = d.id
c)%performance列是一个计算字段,简单计算为:actual / target * 100
d)TOTAL列是仅实际列的总和(不包括目标)
e)立方体具有以下结构: 团体(尺寸) DealerGrp - 经销商 MonthGrp - month_name,键入 摘要字段(度量) 摘要字段 - 金额
我添加了一个派生度量来保存%performance列的值。除了每月的目标和实际列之外,它正确显示,但我无法弄清楚如何提供其值(参见上面c项中的公式) 。 实现这一目标的最佳方法是什么?
如何计算总列数?
非常感谢任何帮助。