欢迎光临
我们一直在努力

任意时间段量的统计-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

如果查询时间段是维中的成员,那么这段时间的量的汇总可以直接得出!(缺省状态下,维中成员是按级别
汇总的),如查询1997年或1997年3月的汇总,可以使用以下语句:
select
    {[time2].[1997]} on columns,
   {[customers].[country].members} on rows
from sales
where ([measures].[store sales])
或[time].[1997].[q1].[3]
但很多情况下,客户希望得到任意时间段的汇总!通常,我们可以这样实现:
如:1997.1.8–1997.5.13
with member [time2].[1997.1.8–1997.5.13] as sum([time2].[1997].[q1].[1].[8]:[time2].[1997].[q2].[5].[13])
select
    {[time2].[1997.1.8–1997.5.13]} on columns,
   {[customers].[country].members} on rows
from sales
where ([measures].[store sales])

注意事项:
1)时间段的起始和结束日期必须是同一级别;
2)未知系统是否会优化查询,所以尽可能使用聚集:如1997.1.8–1997.5.13可以分解为:
sum([time2].[1997].[q1].[1].[8]:[time2].[1997].[q1].[1].[31])+
sum([time2].[1997].[q1].[2]:[time2].[1997].[q1].[3])+
[time2].[1997].[q2].[4]+
sum([time2].[1997].[q2].[5].[1]:[time2].[1997].[q2].[5].[13])
分段尽可能优化,并且可以使用减法!!
如:
sum([time2].[1997].[q1]:[time2].[1997].[q2])-
sum([time2].[1997].[q1].[1].[1]:[time2].[1997].[q1].[1].[7])-
sum([time2].[1997].[q2].[5].[14]:[time2].[1997].[q2].[6].[30])

以上个人意见,仅供参考!

 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 任意时间段量的统计-数据库专栏,SQL Server
分享到: 更多 (0)