MDX查询查找员工薪水超过5000
select
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} on columns,
NON EMPTY
{
(
[Department].[All Department],
[Position].[All Position],
[Employee].[All Employee])
} on rows
from Salary
where
[Measures].[Total Salary]>5000
我的架构
<Schema name="Foodmart">
<Cube name="Salary" visible="true" cache="true" enabled="true">
<Table name="employee" alias="">
</Table>
<Dimension type="StandardDimension" visible="true" foreignKey="department_id" name="Department">
<Hierarchy name="All Department" visible="true" hasAll="true" allMemberName="All Department" primaryKey="department_id" primaryKeyTable="department">
<Table name="department">
</Table>
<Level name="Dept" visible="true" column="department_description" uniqueMembers="true">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" foreignKey="position_id" name="Position">
<Hierarchy name="All Position" visible="false" hasAll="true" allMemberName="All Position" primaryKey="position_id" primaryKeyTable="position">
<Table name="position">
</Table>
<Level name="position" visible="true" table="position" column="position_title" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" name="Employee">
<Hierarchy name="All Employee" visible="true" hasAll="true" allMemberName="All Employee">
<Table name="employee" alias="">
</Table>
<Level name="New Level 0" visible="true" column="full_name" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Measure name="Total Salary" column="salary" aggregator="sum" visible="true">
</Measure>
<Measure name="Total Employee" column="employee_id" aggregator="distinct-count" visible="true">
</Measure>
</Cube>
</Schema>
答案 0 :(得分:1)
我知道如果您来自slq
它看起来不错,但以下是错误的:
WHERE
[Measures].[Total Salary]>5000
您可以在SELECT
子句中使用过滤器功能:
SELECT
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} ON COLUMNS,
NON EMPTY
{
(
[Department].[All Department],
[Position].[All Position]
)
} ON ROWS
FROM [Salary]
WHERE FILTER(
[Employee].[All Employee].CHILDREN,
[Measures].[Total Salary]>5000
);
以上将过滤员工总薪资大于5000的员工。
如果您喜欢以下内容,过滤器可以绕过整个交叉集,但您将获得返回的所有相应员工的列表:
SELECT
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} ON COLUMNS,
NON EMPTY
FILTER(
{
(
[Department].[All Department],
[Position].[All Position],
[Employee].[All Employee].CHILDREN
)
}
,[Measures].[Total Salary]>5000
) ON ROWS
FROM [Salary];
或者在整个集合中使用HAVING
子句 - 虽然这在逻辑上与上述不同:
SELECT
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} ON COLUMNS,
NON EMPTY
[Department].[All Department]
* [Position].[All Position],
* [Employee].[All Employee].CHILDREN
HAVING [Measures].[Total Salary]>5000 ON ROWS
FROM [Salary];
编辑
如果仍然需要ROWS上的[All EmplyeeS]成员,您可以将过滤器移动到子多维数据集:
SELECT
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} ON COLUMNS,
NON EMPTY
[Department].[All Department]
*[Position].[All Position]
*[Employee].[All Employee]
ON ROWS
FROM
(
SELECT
FILTER(
[Employee].[All Employee].CHILDREN,
[Measures].[Total Salary]>5000
) ON 0
FROM [Salary]
);
答案 1 :(得分:0)
我猜你遇到了空间/内存问题。如果是这样,您可以尝试以下代码:
select
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} on columns,
NON EMPTY
{
NonEmpty(
(
[Department].[All Department] *
[Position].[All Position] *
[Employee].[All Employee]
)
,[Measures].[Total Salary]
)
} having [Measures].[Total Salary] > 5000 on rows
from Salary
NonEmpty
函数将在交叉连接时删除空元组。
编辑1 现在怎么样?
with member [Measures].SalGrtrThan5000
as
IIF
(
[Measures].[Total Salary] > 5000,
1,
NULL
)
select
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} on columns,
NON EMPTY
{
NonEmpty(
(
[Department].[All Department] *
[Position].[All Position] *
[Employee].[All Employee]
)
,[Measures].SalGrtrThan5000
)
}
on rows
from Salary
编辑,使用EXISTS
select
{
[Measures].[Total Employee],
[Measures].[Total Salary]
} on columns,
NON EMPTY
{
FILTER
(
EXISTS (
(
[Department].[All Department] *
[Position].[All Position] *
[Employee].[All Employee]
)
, , "SomeMeasureGroup"
) //EXISTS will remove non-empty tuples this way
, [Measures].[Total Salary] > 5000
)//Filters the set
}
on rows
from Salary
将“SomeMeasureGroup”替换为[Measures].[Total Salary]
所属的度量值组的实际名称。有一个逐个单元格的过滤器,但使用EXISTS
,希望这次会更快。