java - Mondrian的schema中,如何做到同一纬度的不同level数据作为查询条件来用?
PHP中文网
PHP中文网 2017-04-18 10:51:49
0
2
524

如下schema代码片段:

<?xml version="1.0"  encoding="UTF-8" ?>
<Schema name="报表">
    <cube name="cube_qc_pass_item" caption="报表1" encoding="UTF-8">
        <table name="fact_qc_pass_record_item_join">
        <Dimension name="models" foreignKey="model_id" caption="模板">
            <Hierarchy hasAll="true" allMemberName="model_name" primaryKey="id" primaryKeyTable="dim_qc_model">
                <Table name="dim_qc_model" />
                <Level name="model_name" column="name" caption="模板"/>
                <Level name="model_id" column="id" caption="model_id"/>
            </Hierarchy>
        </Dimension>
        <Measure name="times" column="id" aggregator="count" formatString="#,###0" datatype="Numeric" caption="总量"/>
    </cube>
</Schema>

我想要在使用mdx查询的时候,使用model_name显示,使用model_id作为查询条件限制某个model_id,该如何书写mdx语句?

已经有如下错误的mdx语句了

mdx查询语句1:

mdx语句

SELECT
NON EMPTY {Hierarchize({{[Measures].[times], [Measures].[notPass], [Measures].[pass]}})} ON COLUMNS,
NON EMPTY {Hierarchize([models].[model_name].Members)} ON ROWS
FROM [cube_qc_pass_model] where [models].[model_id].[5cda6afa-f837-4603-af27-0915cfb812fd]

如下查询报错:

MondrianException: Mondrian Error:Hierarchy '[models]' appears in more than one independent axis.

mdx查询语句2:

mdx语句

SELECT
NON EMPTY {Hierarchize({{[Measures].[times], [Measures].[notPass], [Measures].[pass]}})} ON COLUMNS,
NON EMPTY Hierarchize(Union(CrossJoin([models].[model_name].Members, CrossJoin([times].[minute].Members, [agent_nos].[agent_no].Members)), CrossJoin([models].[model_id].[5cda6afa-f837-4603-af27-0915cfb812fd], CrossJoin([times].[minute].Members, [agent_nos].[agent_no].Members)))) ON ROWS
FROM [cube_qc_pass_model]

结果:
无法进行查询

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
大家讲道理
  1. In fact, according to the syntax of MDX, you cannot place different levels of the same latitude in multiple places, such as one in rows and one in columns, or one in rows or columns and one in the where clause, like The first failed statement in the question

  2. During cross-query, since different levels of the same dimension are used (not to mention that the two levels here are actually one-to-one correspondence), and one level is filtered, the other level is not filtered,

迷茫

I haven’t found a good solution yet, so I changed the direction and realized the demand. Let me share it:

First rewrite the schema file and split model_name and model_id into two dimensions:

<?xml version="1.0"  encoding="UTF-8" ?>
<Schema name="报表">
    <cube name="cube_qc_pass_item" caption="报表" encoding="UTF-8">
        <table name="fact_qc_pass_record_item_join">
        <Dimension name="models" foreignKey="model_id" caption="模板">
            <Hierarchy hasAll="true" allMemberName="model_name" primaryKey="id" primaryKeyTable="dim_qc_model">
                <Table name="dim_qc_model" />
                <Level name="model_name" column="name" caption="模板"/>
            </Hierarchy>
        </Dimension>
        <Dimension name="model_ids" foreignKey="model_id" caption="模板id">
            <Hierarchy hasAll="true" allMemberName="model_id" primaryKey="id" primaryKeyTable="dim_qc_model">
                <Table name="dim_qc_model" />
                <Level name="model_id" column="id" caption="model_id"/>
            </Hierarchy>
        </Dimension>
        <Measure name="times" column="id" aggregator="count" formatString="#,###0" datatype="Numeric" caption="总量"/>
    </cube>
</Schema>

Use the following statement to query the data:

SELECT
NON EMPTY {Hierarchize({{[Measures].[times], [Measures].[notPass], [Measures].[pass]}})} ON COLUMNS,
NON EMPTY CrossJoin([models].[model_name].Members, CrossJoin([times].[minute].Members, [agent_nos].[agent_no].Members)) ON ROWS
FROM [cube_qc_pass_model] where [model_ids].[model_id].[5cda6afa-f837-4603-af27-0915cfb812fd]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template