使用 MDX 进行子选择

发布于 2024-08-25 17:19:05 字数 1026 浏览 3 评论 0原文

问候堆栈溢出社区。

我最近开始在 SSAS2008 中构建 OLAP 多维数据集,但遇到了困难。如果有人至少能指出我正确的方向,我将不胜感激。

情况:两个事实表,同一个多维数据集。 FactCalls 保存有关订阅者拨打的电话的信息,FactTopups 保存充值数据。这两个表都有许多共同的维度,其中之一是订阅者维度。

FactCalls             FactTopups
订阅者密钥      订阅者密钥
通话时长        DateKey
通话费用           充值价值 ...

我想要实现的是能够根据过去 7 天内为其帐户充值的不同订阅者构建 FactCalls 报告。

我基本上正在寻找与 SQL 等效的 MDX:

select *  
  from FactCalls  
 where SubscriberKey in 
       ( select distinct SubscriberKey from FactTopups where ... );  

我尝试为包含 SubscriberKey 的两个表创建一个退化维度并执行以下操作:

Exist( 
         [Calls Degenerate].[Subscriber Key].Children, 
         [Topups Degenerate].[Subscriber Key].Children 
     )

没有成功。

亲切的问候,

文斯

Greetings stack overflow community.

I've recently started building an OLAP cube in SSAS2008 and have gotten stuck. I would be grateful if someone could at least point me towards the right direction.

Situation: Two fact tables, same cube. FactCalls holds information about calls made by subscribers, FactTopups holds topup data. Both tables have numerous common dimensions one of them being the Subscriber dimension.

FactCalls             FactTopups
SubscriberKey      SubscriberKey
CallDuration         DateKey
CallCost               Topup Value
...

What I am trying to achieve is to be able to build FactCalls reports based on distinct subscribers that have topped up their accounts within the last 7 days.

What I am basically looking for an MDX equivalent to SQL's:

select *  
  from FactCalls  
 where SubscriberKey in 
       ( select distinct SubscriberKey from FactTopups where ... );  

I've tried creating a degenerate dimension for both tables containing SubscriberKey and doing:

Exist( 
         [Calls Degenerate].[Subscriber Key].Children, 
         [Topups Degenerate].[Subscriber Key].Children 
     )

Without success.

Kind regards,

Vince

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梓梦 2024-09-01 17:19:05

您可能会发现类似以下内容的效果会更好。过滤器方法将被迫迭代每个订阅者,而 NonEmpty() 函数可以利用存储引擎中的优化。

select non empty{ 
        [Measures].[Count], 
        [Measures].[Cost], 
        [Measures].[Topup Value] 

      } on columns, 
      { 
NonEmtpy( [Subscriber].[Subscriber Key].Children,     
            ( [Measures].[Topups Count],     
              [Topup Date].[Calendar].[Month Name].&[2010]&[3] ) )
   } on rows 
 from [Calls] ; 

You would probably find something like the following would perform better. The filter approach will be forced to iterate through each subscriber, while the NonEmpty() function can take advantage of optimizations in the storage engine.

select non empty{ 
        [Measures].[Count], 
        [Measures].[Cost], 
        [Measures].[Topup Value] 

      } on columns, 
      { 
NonEmtpy( [Subscriber].[Subscriber Key].Children,     
            ( [Measures].[Topups Count],     
              [Topup Date].[Calendar].[Month Name].&[2010]&[3] ) )
   } on rows 
 from [Calls] ; 
信愁 2024-09-01 17:19:05

您知道有时最简单、最明显的解决方案却不知何故让您困惑吗?嗯,这显然是其中之一。他们说“MDX 不是 SQL”,我现在知道他们的意思了。我一直从完全 SQL 的角度来研究这个问题,完全忽略了过滤命令的明显使用。

with set [OnlyThoseWithTopupsInMarch2010] as
    filter( 
            [Subscriber].[Subscriber Key].Children, 
            ( [Measures].[Topups Count], 
              [Topup Date].[Calendar].[Month Name].&[2010]&[3] ) > 0 
          )

select non empty{
        [Measures].[Count],
        [Measures].[Cost],
        [Measures].[Topup Value]

      } on columns,
      non empty{ [Test] } on rows
 from [Calls] ; 

简单得令人尴尬。

You know how sometimes it's the simplest and most obvious solutions that somehow elude you? Well, this is apparently one of them. They say "MDX is not SQL" and I now know what they mean. I've been working at this from an entirely SQL point of view, completely overlooking the obvious use of the filter command.

with set [OnlyThoseWithTopupsInMarch2010] as
    filter( 
            [Subscriber].[Subscriber Key].Children, 
            ( [Measures].[Topups Count], 
              [Topup Date].[Calendar].[Month Name].&[2010]&[3] ) > 0 
          )

select non empty{
        [Measures].[Count],
        [Measures].[Cost],
        [Measures].[Topup Value]

      } on columns,
      non empty{ [Test] } on rows
 from [Calls] ; 

Embarrassingly simple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文