我的问题是这样的,立方体里有某业务的金额,需要查出每个客户所有金额中产品A的金额占比,还要占比区间,mdx如下:
- SQL code
with member [Measures].[产品A金额] as sum({[Prod].[Prod_Name].&[产品A]},[Measures].[Amount])member [Measures].[产品A占比] as [Measures].[产品A金额]/[Measures].[Amount] //, FORMAT_STRING ='0.00%'member [Measures].[产品A占比区间] as case when [Measures].[产品A占比]<0.3 then '30%以下' when [Measures].[产品A占比]>=0.3 and [Measures].[产品A占比]<0.5 then '30%至50%' else '50%以上' end select { [Measures].[Amount] ,[Measures].[产品A金额] ,[Measures].[产品A占比] ,[Measures].[产品A占比区间] } on 0,non empty [Big_Brand_Cust].[Cust_Name].[Cust_Name] on 1from [BIG_BRAND_SFE_001]where {[Date].[月份].&[2012-02-01T00:00:00]}
如果不加[产品A占比区间]这段case语句,得出的结果是正常的,只显示出有业务发生的客户62条数据,但是如果加上这段case语句,就显示出了所有的客户,数据量达到了好几万且金额等全是null,哪里出问题了呢?
------解决方案--------------------
- SQL code
--数据库的表数据是不是有些数据是NULL?判断一下应该就可以了with member [Measures].[产品A金额] as sum({[Prod].[Prod_Name].&[产品A]},[Measures].[Amount])member [Measures].[产品A占比] as [Measures].[产品A金额]/[Measures].[Amount] //, FORMAT_STRING ='0.00%'member [Measures].[产品A占比区间] as case ISNULL([Measures].[产品A占比],0) when [Measures].[产品A占比]<0.3 then '30%以下' when [Measures].[产品A占比]=0 then '0' when [Measures].[产品A占比]>=0.3 and [Measures].[产品A占比]<0.5 then '30%至50%' else '50%以上' end select { [Measures].[Amount] ,[Measures].[产品A金额] ,[Measures].[产品A占比] ,[Measures].[产品A占比区间] } on 0,non empty [Big_Brand_Cust].[Cust_Name].[Cust_Name] on 1from [BIG_BRAND_SFE_001]where {[Date].[月份].&[2012-02-01T00:00:00]}