SELECT
{[Measures].[Imports - Tons]
, [Measures].[Imports - Metric Tonnes]
, [Measures].[Import Customs Value] } ON COLUMNS,
{CROSSJOIN (
[Date].[Month Year].members
,[Country].[Country Name].members
,[Steel Mill Product].[Steel Mill Product Name].[Plates-Cut Length]
,[Concordance].[HTS 10 Digit Code].members) }
ON ROWS
FROM [AISISteel]
WHERE ([Date].[Year].[2014], [Concordance].[HTS 2 Digit Code].[72])
我有这个MDX查询 我想要取回所有这些数据,但只返回Import-Tons> 0的数据。我该怎么做?
答案 0 :(得分:5)
您可以尝试使用FILTER
功能:
SELECT
{[Measures].[Imports - Tons]
, [Measures].[Imports - Metric Tonnes]
, [Measures].[Import Customs Value] } ON COLUMNS,
FILTER(
{CROSSJOIN (
[Date].[Month Year].members
,[Country].[Country Name].members
,[Steel Mill Product].[Steel Mill Product Name].[Plates-Cut Length]
,[Concordance].[HTS 10 Digit Code].members) }
, [Measures].[Imports - Tons] > 0
)
ON ROWS
FROM [AISISteel]
WHERE ([Date].[Year].[2014], [Concordance].[HTS 2 Digit Code].[72])
此外,很少使用的HAVING
子句是您的可能选项
SELECT
{[Measures].[Imports - Tons]
, [Measures].[Imports - Metric Tonnes]
, [Measures].[Import Customs Value] }
ON COLUMNS,
{CROSSJOIN (
[Date].[Month Year].members
,[Country].[Country Name].members
,[Steel Mill Product].[Steel Mill Product Name].[Plates-Cut Length]
,[Concordance].[HTS 10 Digit Code].members) }
HAVING [Measures].[Imports - Tons] > 0
ON ROWS
FROM [AISISteel]
WHERE ([Date].[Year].[2014], [Concordance].[HTS 2 Digit Code].[72])
同样只是为了简洁,CROSSJOIN
功能有一个快捷方式,几乎总是首选:
SELECT
{[Measures].[Imports - Tons]
, [Measures].[Imports - Metric Tonnes]
, [Measures].[Import Customs Value] }
ON COLUMNS,
{[Date].[Month Year].members*
[Country].[Country Name].members*
[Steel Mill Product].[Steel Mill Product Name].[Plates-Cut Length]*
[Concordance].[HTS 10 Digit Code].members}
HAVING [Measures].[Imports - Tons] > 0
ON ROWS
FROM [AISISteel]
WHERE ([Date].[Year].[2014], [Concordance].[HTS 2 Digit Code].[72])
修改
如果将上述内容与以下内容进行比较,执行时间会有很大差异吗?
SELECT
{[Measures].[Imports - Tons]
, [Measures].[Imports - Metric Tonnes]
, [Measures].[Import Customs Value] } ON COLUMNS,
FILTER(
NONEMPTY(
[Date].[Month Year].members*
[Country].[Country Name].members*
[Steel Mill Product].[Steel Mill Product Name].[Plates-Cut Length]*
[Concordance].[HTS 10 Digit Code].members
,[Measures].[Imports - Tons]
)
,[Measures].[Imports - Tons] > 0
)
ON ROWS
FROM [AISISteel]
WHERE ([Date].[Year].[2014], [Concordance].[HTS 2 Digit Code].[72])