MDX语句的特点:
大小写不分。members等于Members;downloads等于Downloads
维度的统计量指定要选择准确。downloads等于[Downloads]
[]可以少,不能多。members外部不能有[],否则报错
TopCount函数格式。
members是属性中所有成员的枚举。
同一维度下的属性组合,用Hierarchize:
SELECT
NON EMPTY {[Measures].[Downloads]} ON COLUMNS,
NON EMPTY {Hierarchize({{[appTag.default].[dimstore].Members}, {[appTag.default].[Class].Members}})} ON ROWS
FROM [aso]
不同维度的属性组合,用CrossJoin:
SELECT
NON EMPTY {[Measures].[Downloads]} ON COLUMNS,
NON EMPTY CrossJoin([dimInterval.default].[Interval].Members, CrossJoin([dimStoreName.default].[storeName].Members, [dimDate.default].[year].Members)) ON ROWS
FROM [aso]
举几个具体的例子:
下面两个语句是一样的:
1.SELECT
NON EMPTY {downloads} ON COLUMNS,
TopCount([dimStoreName].[storeName].members,2,[downloads]) ON ROWS
FROM [aso]
2.SELECT
downloads ON COLUMNS,
{TopCount([dimStoreName].[storeName].members,2,[measures].[downloads])}ON ROWS
FROM [aso]
aso是一个cube,总体。如果需要在结果集中筛选出某个属性取特定值的结果,用where 子句
略(有空再写)
查看downloads的top 15:前15计算函数topcount(set,topK,依据统计量),排序后取前15
SELECT
NON EMPTY {downloads} ON COLUMNS,
TopCount([dimApp].[appName].members,15,[downloads]) ON ROWS
FROM [aso]
如果查询跨越来两个不同维度,需要crossjoin,
SELECT
NON EMPTY {downloads} ON COLUMNS,
TopCount(
CrossJoin([dimStoreName.default].[storeName].Members,[dimApp].[appName].members),15,[downloads]
) ON ROWS
FROM [aso]
先交叉,确定查询结果集(交叉连接),再筛选
不能先统计,后交叉,错误:
SELECT
NON EMPTY {downloads} ON COLUMNS,
CrossJoin([dimStoreName.default].[storeName].Members,
(topcount([dimApp].[appName].members,15,[downloads]))
)
ON ROWS
FROM [aso]
top5实例进阶:
SELECT
{[downloads]} ON COLUMNS,
Generate(
TopCount([dimStore].[store_name].Members, 5, [downloads]),
{ [dimStore].CurrentMember } * TopCount( [appName].[AppName].Members, 5, ([downloads],[dimStore].CurrentMember) )
) on ROWS
FROM [ASO]
标准格式的例子,猜猜什么意思:
SELECT
NON EMPTY {[Measures].[Downloads], [Measures].[AppCount]} ON COLUMNS,
NON EMPTY Hierarchize(
Union( CrossJoin({[appTag.default].[anzhi]}, [dimDate.default].[year].Members),
Union( CrossJoin({[appTag.default].[anzhi]}, [dimDate.default].[day].Members),
Union( CrossJoin({[appTag.default].[hiapk]}, [dimDate.default].[year].Members),
CrossJoin({[appTag.default].[hiapk]}, [dimDate.default].[day].Members)
)
)
)
) ON ROWS
FROM [aso]
骂娘了吗?
解析一下,简化的例子:
SELECT
NON EMPTY {[Measures].[Downloads]} ON COLUMNS,
NON EMPTY Hierarchize(
Union(CrossJoin([dimDate.default].[year].Members, [appTag.default].[dimstore].Members),
Union(CrossJoin([dimDate.default].[month].Members, [appTag.default].[dimstore].Members),
CrossJoin([dimDate.default].[day].Members, [appTag.default].[dimstore].Members)
)
)
) ON ROWS
FROM [aso]
执行结果如下:
如果只是date维度的下的月日年,很简单,Hierarchize就可以了,如
SELECT
NON EMPTY {[Measures].[Downloads]} ON COLUMNS,
NON EMPTY {Hierarchize({{[dimDate.default].[year].Members}, {[dimDate.default].[month].Members}, {[dimDate.default].[day].Members}})} ON ROWS
FROM [aso]
但是当两个维度下的多个维度组合在一起,就要进行笛卡映射,分别crossjoin,在总体合并。两个维度属性集,分别crossjoin,然后再将所有crossjoin结果集进行union。
union就是并集(合并两个结果集)。
intersect是交集