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

KB3868: SQL for a MicroStrategy report is missing the GROUP BY clause when the attributes in the template are at the lowest level of their respective dimension and/or those attributes are the only attributes appearing in the fact table


Community Admin

• Strategy


SQL for a MicroStrategy report is missing the GROUP BY clause when the attributes in the template are at the lowest level of their respective dimension and/or those attributes are the only attributes appearing in the fact table

SYMPTOM:
When a user runs a report that includes a template with attributes at the lowest level of their respective dimensions and/or the IDs for those attributes are the only IDs included in the fact table, the SQL is missing the GROUP BY clause:
select a24.STORE_NBR STORE_NBR,
    a24.STORE_DESC STORE_DESC,
    a23.CLASS_NBR CLASS_NBR,
    a23.CLASS_DESC CLASS_DESC,
    a23.ITEM_NBR ITEM_NBR,
    a23.ITEM_DESC ITEM_DESC,
    (a21.REG_SLS_QTY) REGULARSALE,
from STORE_ITEM_00 a21,
    LOOKUP_ITEM a23,
    LOOKUP_STORE a24
where a21.CLASS_NBR = a23.CLASS_NBR
    and a21.ITEM_NBR = a23.ITEM_NBR
    and a21.STORE_NBR = a24.STORE_NBR
This SQL returns the whole fact table instead of grouping the attributes according to the template. The correct SQL is as follows:
select a24.STORE_NBR STORE_NBR,
    max(a24.STORE_DESC) STORE_DESC,
    a23.CLASS_NBR CLASS_NBR,
    max(a23.CLASS_DESC) CLASS_DESC,
    a23.ITEM_NBR ITEM_NBR,
    max(a23.ITEM_DESC) ITEM_DESC,
    sum(a21.REG_SLS_QTY) REGULARSALE
from STORE_ITEM_00   a21,
    LOOKUP_ITEM   a23,
    LOOKUP_STORE   a24
where a21.CLASS_NBR = a23.CLASS_NBR and
    a21.ITEM_NBR = a23.ITEM_NBR and
    a21.STORE_NBR = a24.STORE_NBR
group by   a24.STORE_NBR,
    a23.CLASS_NBR,
    a23.ITEM_NBR
CAUSE:
For the above SQL, the template includes the attributes Store and Serial Number, along with a COUNT(Cost_Amt) metric, as follows:
 

ka04W000000OhM5QAK_0EM440000002GLE.gif

 
The fact table STORE_ITEM_00 has the following structure:
 
 

 
Column NameData TypeDefault ValueUSER_IDINT USER_NAMEVARCHAR(50) DEPT_IDINT0REGION_IDINT0LASTMODIFIEDTIMESTAMP1900-01-01USER_IDUSER_NAMEDEPT_IDREGION_IDLASTMODIFIED456Turing, Alan15211900-01-011731Hellman, Martin152371945-10-021892Rivest, Ronald2312004-08-172645Babbage, Charles12351900-01-014654Diffie, Whitfield156571900-01-014789Dijkstra, Edsger Wybe31472002-08-067859Gosling, James34541955-05-19Form nameForm categoryFormat typeExpressionIDIDNumberUSER_IDNameDESCTEXTUSER_NAMELast ModifiedNoneDatetimeLASTMODIFIEDUSERLASTMODIFIEDTuring, Alan Hellman, Martin1945-10-02Rivest, Ronald2004-08-17Babbage, Charles Diffie, Whitfield Dijkstra, Edsger Wybe2002-08-06Gosling, James1955-05-19STORE_ITEM_00STORE_IDCLASS_IDITEM_IDFact columns

 
Column NameData TypeDefault ValueUSER_IDINT USER_NAMEVARCHAR(50) DEPT_IDINT0REGION_IDINT0LASTMODIFIEDTIMESTAMP1900-01-01USER_IDUSER_NAMEDEPT_IDREGION_IDLASTMODIFIED456Turing, Alan15211900-01-011731Hellman, Martin152371945-10-021892Rivest, Ronald2312004-08-172645Babbage, Charles12351900-01-014654Diffie, Whitfield156571900-01-014789Dijkstra, Edsger Wybe31472002-08-067859Gosling, James34541955-05-19Form nameForm categoryFormat typeExpressionIDIDNumberUSER_IDNameDESCTEXTUSER_NAMELast ModifiedNoneDatetimeLASTMODIFIEDUSERLASTMODIFIEDTuring, Alan Hellman, Martin1945-10-02Rivest, Ronald2004-08-17Babbage, Charles Diffie, Whitfield Dijkstra, Edsger Wybe2002-08-06Gosling, James1955-05-19STORE_ITEM_00STORE_IDCLASS_IDITEM_IDFact columns

 
Column NameData TypeDefault ValueUSER_IDINT USER_NAMEVARCHAR(50) DEPT_IDINT0REGION_IDINT0LASTMODIFIEDTIMESTAMP1900-01-01USER_IDUSER_NAMEDEPT_IDREGION_IDLASTMODIFIED456Turing, Alan15211900-01-011731Hellman, Martin152371945-10-021892Rivest, Ronald2312004-08-172645Babbage, Charles12351900-01-014654Diffie, Whitfield156571900-01-014789Dijkstra, Edsger Wybe31472002-08-067859Gosling, James34541955-05-19Form nameForm categoryFormat typeExpressionIDIDNumberUSER_IDNameDESCTEXTUSER_NAMELast ModifiedNoneDatetimeLASTMODIFIEDUSERLASTMODIFIEDTuring, Alan Hellman, Martin1945-10-02Rivest, Ronald2004-08-17Babbage, Charles Diffie, Whitfield Dijkstra, Edsger Wybe2002-08-06Gosling, James1955-05-19STORE_ITEM_00STORE_IDCLASS_IDITEM_IDFact columns

 
Column NameData TypeDefault ValueUSER_IDINT USER_NAMEVARCHAR(50) DEPT_IDINT0REGION_IDINT0LASTMODIFIEDTIMESTAMP1900-01-01USER_IDUSER_NAMEDEPT_IDREGION_IDLASTMODIFIED456Turing, Alan15211900-01-011731Hellman, Martin152371945-10-021892Rivest, Ronald2312004-08-172645Babbage, Charles12351900-01-014654Diffie, Whitfield156571900-01-014789Dijkstra, Edsger Wybe31472002-08-067859Gosling, James34541955-05-19Form nameForm categoryFormat typeExpressionIDIDNumberUSER_IDNameDESCTEXTUSER_NAMELast ModifiedNoneDatetimeLASTMODIFIEDUSERLASTMODIFIEDTuring, Alan Hellman, Martin1945-10-02Rivest, Ronald2004-08-17Babbage, Charles Diffie, Whitfield Dijkstra, Edsger Wybe2002-08-06Gosling, James1955-05-19STORE_ITEM_00STORE_IDCLASS_IDITEM_IDFact columns

 
Column NameData TypeDefault ValueUSER_IDINT USER_NAMEVARCHAR(50) DEPT_IDINT0REGION_IDINT0LASTMODIFIEDTIMESTAMP1900-01-01USER_IDUSER_NAMEDEPT_IDREGION_IDLASTMODIFIED456Turing, Alan15211900-01-011731Hellman, Martin152371945-10-021892Rivest, Ronald2312004-08-172645Babbage, Charles12351900-01-014654Diffie, Whitfield156571900-01-014789Dijkstra, Edsger Wybe31472002-08-067859Gosling, James34541955-05-19Form nameForm categoryFormat typeExpressionIDIDNumberUSER_IDNameDESCTEXTUSER_NAMELast ModifiedNoneDatetimeLASTMODIFIEDUSERLASTMODIFIEDTuring, Alan Hellman, Martin1945-10-02Rivest, Ronald2004-08-17Babbage, Charles Diffie, Whitfield Dijkstra, Edsger Wybe2002-08-06Gosling, James1955-05-19STORE_ITEM_00STORE_IDCLASS_IDITEM_IDFact columns

 
Store, Class, and Item are the only attributes related to this table, so the SQL Generation Engine assumes that they constitute the primary key for this table. Therefore, it generates SQL without a Group By expression.
 
There might be a situation in which the attributes included in the template do not constitute the primary key, so the SQL may be returning the whole table, which in most cases is not desired.
 
ACTION:
If the attributes included in the template do not constitute the primary key, the following actions must be taken to correct the issue:

  • In Strategy Developer, open the folder Project Source\Project\Schema Objects\Tables.
  • Double-click on the fact table included in the SQL. In the above example, it is STORE_ITEM_00.
  • Uncheck the box labeled 'The key specified is the true key for the warehouse table,' as displayed below.
     
ka04W000000OhM5QAK_0EM440000002GL8.gif
  • Save and close this window.
  • Open the Schema menu and select 'Update Schema….'
  • In the next screen, check the three boxes and click on the 'Update' button.
  • Run the same report again.

Comment

0 comments

Details

Knowledge Article

Published:

May 24, 2017

Last Updated:

May 24, 2017