2016-10-03 62 views
0

需要查询ssas立方体的帮助。MDX查询复杂度

例如我有:

1)尺寸表合同。表具有列:contract_id,customer_id,customer_type。一个客户可能有多个合同,contract_id是独一无二的,因此,例如数据可能是:

enter image description here

2)事实表交易。表具有列:transaction_id,contract_id,日期,金额。一个合同可能有多个交易(通过contract_id链接维度表和事实表),transacion_id是唯一的。因此,例如,数据可能是:

enter image description here

我希望得到积极的(即具有交易)和无源(即没有交易)的客户按客户类别计数。

enter image description here

感谢您的帮助。

+0

很抱歉,但我不明白,公司如何能拥有活跃客户群与给定的样本...我看到2无源那里, 0激活。 –

+0

对不起,不好的例子。我编辑了这篇文章。 – NoWayOut

+0

你试过了什么mdx? – whytheq

回答

0

这可能是一个办法,找东西更“优雅”

with c as (
    select distinct 
      c.customer_type, 
      c.customer_id, 
      case when exists (
          select null 
          from transactions t 
          where t.contract_id = c.contract_id 
          --and t.[date] < @parameterx 
          --and t.[date] > @parametery) 
      then 1 else 0 end as contract_exists 
from customers c 
) 
select 
    customer_type, 
    sum(case when contract_exists = 1 then 1 else 0 end), 
    sum(case when contract_exists = 0 then 1 else 0 end) 
from c 
group by customer_type 
+0

是的。但是,如果我们将参数交易日期和交易日期添加到?我们可以得到预期的结果而不用附加字段附加维数表吗? – NoWayOut

+0

您可以将这些参数添加到'select null from transactions ...'部分的'where'子句中......' –

+0

但是由于帖子标题说我想用mdx从多维数据集中查询并在稍后使用ssrs查询。您建议使用已经过滤的数据生成立方体? – NoWayOut