EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB10044: Incorrect SQL is generated when a child attribute has multiple parents and the report filters on the many-to-many parent in MicroStrategy SQL Engine


Community Admin

• Strategy


Incorrect SQL is generated when a child attribute has multiple parents and the report filters on the many-to-many parent in MicroStrategy SQL Engine

SYMPTOM:
In the Strategy Tutorial project, a user wishes to see the total revenue for Sony products that were listed in the Spring 2001 catalog. The user creates a new report as follows:
 

  • Template: Brand attribute, Revenue metric
  • Filter: Brand in list (Sony) and Catalog in list (Spring 2001)

Note: This report will return no results in Strategy Tutorial because the relationship table between Item and Catalog is empty.
 
Examining the report Structured Query Language (SQL), the user observes that the query will actually return the revenue for all Sony products, not only those products that were listed in the Spring 2001 catalog:
 
select   a12.BRAND_ID BRAND_ID,
   max(a13.BRAND_DESC) BRAND_DESC,
   sum(a11.TOT_DOLLAR_SALES) WJXBFS1
from   ITEM_MNTH_SLS   a11
   join   LU_ITEM   a12
    on    (a11.ITEM_ID = a12.ITEM_ID)
   join   LU_BRAND   a13
    on    (a12.BRAND_ID = a13.BRAND_ID)
where   (((a12.BRAND_ID)
in   (select   c22.BRAND_ID
   from   REL_CAT_ITEM   c21
      join   LU_ITEM   c22
       on    (c21.ITEM_ID = c22.ITEM_ID)
   where   c21.CAT_ID in (5)))
and a12.BRAND_ID in (215))
group by   a12.BRAND_ID
The subquery, shown in boldface, identifies all the brands that had an item in the specified catalog. The main query then sums the total dollar sales for all the items belonging to the Sony brand (if that brand was in the catalog).
 
To obtain the desired results, the subquery should be evaluated at Item level, not Brand level.
 
CAUSE:
The attributes on the template combined with the attributes in the report filter are all at a higher level than Item. The report level is (Brand, Catalog). The Strategy Engine is designed to evaluate filters at report level unless otherwise specified.
 
When set qualifications are used (metric or relationship filters), users can define the output level of the set to be a user-selected set of attributes (or, in the case of metric qualifications, the default metric level or report level). The qualification here is an attribute qualification; thus, the user does not have a chance to specify the output level.
 
ACTION:
Two possible resolutions are available:
 

  • Add a dummy filter to the report filter, based on the child attribute (Item) where the ID is not null. This will lower the report level to the child attribute, causing the subquery to be evaluated at the child level:
ka04W000000OhiHQAS_0EM440000002Fx7.gif
  •  
    select   a12.BRAND_ID BRAND_ID,
       max(a13.BRAND_DESC) BRAND_DESC,
       sum(a11.TOT_DOLLAR_SALES) WJXBFS1
    from   ITEM_MNTH_SLS   a11
       join   LU_ITEM   a12
        on    (a11.ITEM_ID = a12.ITEM_ID)
       join   LU_BRAND   a13
        on    (a12.BRAND_ID = a13.BRAND_ID)
    where   (((a11.ITEM_ID)
    in   (select   c21.ITEM_ID    from   REL_CAT_ITEM   c21    where   c21.CAT_ID in (5)))
    and a12.BRAND_ID in (215)
    and a11.ITEM_ID is not null)
    group by   a12.BRAND_ID
  • Use a relationship filter, Set of Item where (Catalog = Spring 2001) Relate by system default.
     
    This gives the user more direct control over the output level, but it also results in less efficient SQL. In this case, the relationship filter replicates the many-to-many relationship between Catalog and Item. The Strategy Engine cannot assume that the relationship filter will be the same; therefore, it renders the same subquery twice: once for the many-to-many relationship, and once for the relationship filter.
ka04W000000OhiHQAS_0EM440000002Fx8.gif
  •  
    select   a12.BRAND_ID BRAND_ID,
       max(a13.BRAND_DESC) BRAND_DESC,
       sum(a11.TOT_DOLLAR_SALES) WJXBFS1
    from   ITEM_MNTH_SLS   a11
       join   LU_ITEM   a12
        on    (a11.ITEM_ID = a12.ITEM_ID)
       join   LU_BRAND   a13
        on    (a12.BRAND_ID = a13.BRAND_ID)
    where   (((a11.ITEM_ID)
    in   (select   c21.ITEM_ID    from   REL_CAT_ITEM   c21    where   c21.CAT_ID in (5)))
    and ((a11.ITEM_ID)
    in   (select   r12.ITEM_ID    from   REL_CAT_ITEM   r12    where   r12.CAT_ID in (5)))
    and a12.BRAND_ID in (215))
    group by   a12.BRAND_ID

Comment

0 comments

Details

Knowledge Article

Published:

April 21, 2017

Last Updated:

April 21, 2017