OBIEE: Incorrect SQL - with count function uses ORDER BY instead GROUP BY

I made a basic report that is a client count; I want to know how many clients the company have.
But, when I run this report, OBIEE generates a ORDER BY sentence, instead a GROUP BY. Remember that I'm using count function, that is a agregation.
The SQL generated was:
select 'N0' as c1,
count(*) as c2
from
(select distinct T1416.CLIENT_INTER_KEY as c1
from
(select *
from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
(select *
from prd.D_CLIENT) T1416,
(select *
from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
) D1
order by c1
The error that I receive is:
"Query Status: Query Failed: [nQSError: 16001] ODBC error state: S1000 code: -1005018 message: [Sybase][ODBC Driver][Adaptive Server Anywhere]Illegal ORDER BY item Order Item: 'N0',
-- (opt_OrderBy.cxx 429) .
[nQSError: 16011] ODBC error occurred while executing SQLExtendedFetch to retrieve the results of a SQL statement."
If I substitute ORDER BY with GROUP BY and test it in Sybase, Ithe query runs without any problem.
select 'N0' as c1,
count(*) as c2
from
(select distinct T1416.CLIENT_INTER_KEY as c1
from
(select *
from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
(select *
from prd.D_CLIENT) T1416,
(select *
from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
) D1
group by c1
Do you know why OBIEE generates this SQL??? Why uses, with a aggregation function, a ORDER BY and not a GROUP BY? How can I resolve this problem???
Regards,
Susana Figueiredo

Verify your repository design and make sure that you have defined count aggregate on fact column. You would also need to define the content level of each dimension in fact table.

Similar Messages

  • Incorrect parameter with CALL FUNCTION - WE19

    hi! All
    while creating IDOC through WE19 - Start Inbound it creates IDOC with Status - 64."IDoc ready to be transferred to application" "No filters , No conversion , No version change ."
    Incorrect parameter with CALL FUNCTION
    This parameter was "MASSAVEINFOS".
    but i have Included this parameter in my Function module.
    INPUT_METHOD TYPE INPUTMETHD
    MASS_PROCESSING TYPE MASS_PROC
    NO_APPLICATION_LOG LIKE SY-DATAR
    MASSAVEINFOS LIKE MASSSAVINF
    whats the mistake i have done.
    Regards
    Kv

    That will not be possible KV, as the call to the FM is not being made, as far as i see you have completed the needed settings.
    As i do not have access to an SAP system, i suggest that you try below,
    1) Go to WE19, enter the IDOC number and F8.
    2) In this screen, click on Inbound function module.
    3) In the field for inbound function module press F4, it should list your FM name here if all the necessary we42/82/57, BD51 and WE20 have been done correctly.
    Another thing that you can try is, on WE19,
    1) Idoc Number F8
    2) /h - to start Debug
    3) Now click on Standard inbound, in the debug mode press F5 once.
    4) Now put a break point on all message statement
    See where exactly the message of wrong FM is being thrown, it will most probably be after a select statement on one of the tables associated with WE42/82/57/BD51 etc. With this you will where you have missed out.
    All the best !!!
    Regards,
    Chen
    Edited by: Chen K V on Mar 18, 2010 8:55 AM

  • Sql count function in order by clause

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Hi Guys
    Can i ask a quick question. I am trying to retrieve data remotely from a SQL Server via crystal reports.
    Within the Database Expert I have entered a SQL query to retrive the number of (call center) support calls raised by our customers:-
    Select `Primary_Company`, COUNT(`Calls`)From  `SPRT_Issue` GROUP BY  `Primary_Company`ORDER BY  COUNT(`Calls`) desc
    The customer's column is called 'Primary Company' and the calls they raise are in the 'Calls' column. the above is a normal sql query.
    However Crystal fails to run the query and generates an error message :-
    Failed to open a rowset. Details: 420: Driver&#93; Expected lexical element not found: <identifier>
    I dont understand why it wont run. In the ORDER BY clause if i replace field 'Calls' by the field 'Primary Company' then it works.
    I think the problem is that it wont accept the count function in the order by clause. which is what i want it to do i.e display the calls in descending order by each customer.
    Could someone tell me if there is a way around it.
    Thanks
    Krypton

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Thanks Lynn
    I tried your suggestion. But there is one probelm.
    When i sort the data in descending order using the count(calls) field, the data is returned but the customer's name appears multiple times along with their calls raised.
    E.g, if customer Mark raised multiple calls i.e. 2, 5, and 10 calls, then the report will show
    Mark   2
    Mark  5
    Mark 10
    But is there a way to aggregate all the calls for mark and show them only once:
    such as Mark   17
    Thanks

  • Tuning sql with analytic function

    Dear friends I've developed one sql :
    with REP as
    (select /*+ MATERIALIZE */ branch_code,
       row_number() over(partition by branch_code, account order by bkg_date desc  ) R,
             account,
             bkg_date,
             lcy_closing_bal
        from history t
    select REP1.branch_code,
           REP1.account,
           REP1.bkg_date,
           REP1.lcy_closing_bal,
             NULL  AS second,
           REP2.bkg_date        bkg_date2,
           REP2.lcy_closing_bal lcy_closing_bal2,
            NULL  AS third,
           REP3.bkg_date        bkg_date3,
           REP3.lcy_closing_bal lcy_closing_bal3
      from (SELECT * FROM REP WHERE R=1) REP1, (SELECT * FROM REP WHERE R=2) REP2, (SELECT * FROM REP WHERE R=3) REP3
    where
           (REP1.BRANCH_CODE = REP2.BRANCH_CODE(+) AND REP1.ACCOUNT = REP2.ACCOUNT(+)) AND
           (REP1.BRANCH_CODE = REP3.BRANCH_CODE(+) AND REP1.ACCOUNT = REP3.ACCOUNT(+))The point is I want to restrict (tune) REP before it used ,because , as you can see I need maximum three value from REP (where R=1,R=2,R=3) . Which analytic function and with wich options I have to use to receive only 3 values in each branch_code,account groups at the materializing time ?

    Radrigez wrote:
    Dear friends I've developed one sql :
    with REP as
    from (SELECT * FROM REP WHERE R=1) REP1,
    (SELECT * FROM REP WHERE R=2) REP2,
    (SELECT * FROM REP WHERE R=3) REP3
    where
    (REP1.BRANCH_CODE = REP2.BRANCH_CODE(+) AND REP1.ACCOUNT = REP2.ACCOUNT(+)) AND
    (REP1.BRANCH_CODE = REP3.BRANCH_CODE(+) AND REP1.ACCOUNT = REP3.ACCOUNT(+))
    The first step is to put your subquery (which doesn't need to be materialized) into an inline view and restrict the result set on r in (1,2,3) as suggested by thtsang - you don't need to query the same result set three times.
    Then you're looking at a simple pivot operation (assuming the number of rows you want per branch and account is fixed). If you're on 11g search the manuals for PIVOT, on earlier versions you can do this with a decode() or case() operator.
    Step 1 (which could go into another factored subquery) would be something like:
    select
            branch_code, account,
            case r = 1 then bkg_date end bkg_date,
            case r = 1 then lcy_closing_bal end lcy_closing_bal,
            case r = 2 then bkg_date end bkg_date2,
            case r = 2 then lcy_closing_bal end lcy_closing_bal2,
            case r = 3 then bkg_date end bkg_date3,
            case r = 3 then lcy_closing_bal end lcy_closing_bal3
    from
            repThis gives you the eight necessary columns, but still (up to) three rows per branch/account.
    Then you aggregate this (call it rep1) on branch and account.
    select
            branch_code, account,
            max(bkg_date),
            max(lcy_closing_bal),
            max(bkg_date2),
            max(lcy_closing_bal2),
            max(bkg_date3),
            max(lcy_closing_bal3)
    from
            rep1
    group by
            branch_code, account
    order by
            branch_code, accountRegards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>

  • Help with Count function

    Post Author: RJPiekos
    CA Forum: Desktop Intelligence Reporting
    I am trying to use the count function to count the number of unique PO numbers in a column. The program returns a value of "1" even when there are no PO's to be counted. Is there some system setting that i am missing.
    The universe that i am using is a free-hand SQL query to to an MS Access .mdb file. (if that makes a difference)
    Desktop IntelligenceBO 11.5
    Rick

    Post Author: RJPiekos
    CA Forum: Desktop Intelligence Reporting
    Found my problem - 'empty' values in the PO column were not NULL.

  • Can a SQL WITH Clause be used in Materialized View

    Hello,
    Can we use SQL WITH clause in Materialized View.
    Thanks

    Hello,
    Here is an example
    CREATE MATERIALIZED VIEW MV_TEST
    BUILD IMMEDIATE
    REFRESH FORCE ON DEMAND
    AS
    WITH t AS (SELECT owner, object_type, COUNT ( * )
               FROM my_objects
               GROUP BY object_type, owner)
    SELECT *
    FROM t
    WHERE owner IN ('SYS', 'SYSTEM');Regards

  • How to use order by within Group by clause

    Hi All,
    I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
    Select RaceNo,Venue,FP,BP from Race group by RaceNo
    Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
    Can anybody suggest me how to use order by clause that would apply to each group of data.
    Thanks .

    order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
    i hope this eg.l gives u some clarification....
    e.g
    select deptno,count(empno)
    from dept
    group by deptno
    having count(empno) > 10
    order by deptno

  • Derive found flag in SQL with where clause using TABLE(CAST function

    Dear All,
    Stored procedure listEmployees
    ==========================
    CREATE OR REPLACE TYPE STRING_ARRAY AS VARRAY(8000) OF VARCHAR2(15);
    empIdList STRING_ARRAY
    countriesList STRING_ARRAY
    SELECT EMP_ID, EMP_COUNTRY, EMP_NAME, FOUND_FLAG_
    FROM EMPLOYEE WHERE
    EMP_ID IN
    (SELECT * FROM TABLE(CAST(empIdList AS STRING_ARRAY))
    AND EMP_COUNTRY IN
    (SELECT * FROM TABLE(CAST(countriesList AS STRING_ARRAY))
    =================
    I have a stored procedure which lists the employees using above simple query.
    Here I am using table CAST function to find the list of employees in one go
    instead of looping through each and every employee
    Everything fine until requirements forced me to get the FOUND_FLAG as well.
    Now I wanted derive the FOUND_FLAG by using rownum, rowid, decode functions
    but I was not successful
    Can you please suggest if there is any intelligent way to say weather the
    row is found for given parameters in the where clause?
    If not I may have to loop through each set of empIdList, countriesList
    and find the values individually just to set a flag. In this approach I can’t use
    the TABLE CAST function which is efficient I suppose.
    Note that query STRING_ARRAY is an VARRAY. It is very big in size and this procedure
    suppose to handle large sets of data.
    Thanks In advance
    Regards
    Charan
    Edited by: kmcharan on 03-Dec-2009 09:55
    Edited by: kmcharan on 03-Dec-2009 09:55

    If your query returns results, you have found them... so your "FOUND" flag might be a constant,...

  • Odd Error with decode function in Order By Clause

    I am trying to compile a procedure and can't get around an error with a dynamic order by that doesn't make much sense to me. I can repoduce the error with a plain select statment in sql plus so I can rule out a declaration error. Here is an example with 2 numeric columns and a date column.
    select task_id, display_date, remark_id from task_list
    where task_id > 1000
    order by decode('Task_ID', 'Task_ID',Task_ID, 'Display_Date', Display_Date, 'Remark_ID',Remark_ID)
    returns the error:
    select task_id, display_date, remark_id from task_list
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got DATE
    I'm not sure why this error is occuring, because it doesn't even hit the Display_Date field in the Decode statment. If I take the Display_date out of the statement, it runs properly. If I change Display_Date to To_Char(Display_Date) it also runs fine, but the sorting is incorrect. Also I'm running 9.2, and do not want to use dynamic sql to build my query. Any Ideas out there as to the cause of this error?

    I did find a workaround to this issue by breaking the decode statment into three separate statement, but I still think that the way it is written above should work, and may be a bug, or an error that I don't understand fully.
    The Order by was rewritten like this:
    order by decode(pSort, 'Task_ID',Task_ID), decode(pSort, 'Display_Date', Display_Date),
    decode(pSort, 'Remark_ID',Remark_ID);
    Thanks

  • Problem with SaveAs function using random paths.

    The Setup:
    Part 1) I have a folder-level script that allows me to perform a SaveAs function from within forms. I do this as a way to save the document quietly in the background. The effect is that the file is overwritten by a copy of itself. The script is:
    var mySaveAs = app.trustedFunction( function(oDoc,cPath,cFlName)
        app.beginPriv();
        cPath = cPath.replace(/([^\/])$/, "$1/");
        try{
            oDoc.saveAs(cPath + cFlName);
        }catch(e){
            app.alert("Error During Save");
        app.endPriv();
    Part 2) From within my documents, I perform the save by calling the function below:
    function runSave()
    {if(typeof(mySaveAs) == "function") {
        var pathArray = this.path.split("/");
        var myFileName = pathArray[pathArray.length-1];
        var cPath = this.path.slice(0,myFileName);
        mySaveAs(this, cPath, myFileName);
    } else {
        app.alert("Missing Save Function\n" + "Please contact forms administrator");
    Part 3) I have several large forms that utilize an autosave to call the save function according to a time interval of 5 minutes, using:
    app.setInterval(runSave(), 300000);
    The Problem:
    Part 1) The autosave feature works fine and it works silently in the background. However, I start to experience problems when I have two forms open at the same time. If, for example, I have a form from one folder open, and open a form from a second folder, the save feature will sometimes save the active document to it's original folder (as intended, overwriting itself and creating an autosave) or sometimes save to the second document's original folder. This leaves me with an updated (autosaved) copy of the document in the wrong folder, and a non-updated copy in the original folder. This seems to vary depending on which document I opened last and/or which document is currently active. Though I can't seem to find the right combination.
    It's as thought the "this.path" is getting confused.
    Part 2) Worse still, if the two documents have the same name, as is often the case with these forms, any incorrect filing when saving causes an overwrite of the second document and loss of data.
    Part 3) To makes things maddening, this also happens at times when no second folder or second document is open. Instead, the misfiling saves the single, active document to a recently accessed folder. For example, I'll open a local folder and open a Word doc, close the doc and the folder, go to a different folder in a different root (a networked folder), open the form, and it autosaves to the local machine in the folder with the Word doc. So now not only do I have a non-updated copy in my correct folder, I have no idea where the updated copy was actually saved to until I come across it some time later.
    Part 4) Again, worse still, the previously accessed folder might happen to be one that contains a document with the same name, and that document gets overwritten by the autosave. I'll have no idea that the form has been overwritten until I happen to open it some time later and see that it contains data from a totally different form.
    What is going on and how do I stop it?
    Adobe Acrobat X Pro on a PC.

    Thank you, that is helpful to understand. I'd like to keep it as 3 parameters, as all my documents currently output 3 to the trusted function. And I'd still like to keep the error catch, but I'm not sure why the previous trusted function from the tutorial is no longer working, so I just want to run this by you:
    safeSaveAs = app.trustPropagatorFunction(function(theDoc,thePath,theFileName){
        app.beginPriv();
        var fullPath = (thePath + theFileName);  
        try {
            theDoc.saveAs({cPath:fullPath});
        } catch(e) {
            app.alert("Error During Save");
        app.endPriv();
    myTrustedSaveAs = app.trustedFunction(function(theDoc,thePath,theFileName){
            app.beginPriv();
            safeSaveAs(theDoc,thePath,theFileName);
            app.endPriv();

  • Queries with date functions using PreparedStatement for multiple DB

    I am developing application that uses DB independant queries. I am using preparedstatement to process the queries. I need to use date functions for query selection criteria.
    for eg.
    selecting the list of employees who had joined in the last 15 days
    selecting list of employees who had joined between two dates etc.
    where Date Joined field is a Timestamp value. To extract date no DB specific function can be used.
    If I use setMonth, setYear etc.. to set params in the pstmt the query becomes complex in the above case. Can any one throw some light on how to do the above in preparedstatement or any other better alternative.
    Tx a lot

    Hi,
    I did not mean that way. I presume that there is a timestamp value (may be a date too) column in the table. Then based upon your requirement (say before 15 days) pass the value as date (or time stamp) in the query as a parameter.
    String qry = "select * from myTable where join_date <= ?";
    stmt.setDate(1,myDate); // this is where you will have to manipulate the value to suit your DB timestamp or date value; you will have compatibility issues with util.Date and sql.Date so use Calendar class to satisfy.Feel free to mail me if you need further clarifications to [email protected]
    Cheers,
    Sekar

  • Issue with Bookmark functionality (using java script) in WAD.

    Hi,
    I am working on a WAD report and instead of using the default bookmark functionality within WAD, i use a java code to get the bookmark url in a new window.
    But the problem is the java code is not working consistently at all times.
    Issue1: If i click on the bookmark button on the report for the first time, it will open up a new window with the bookmark link. But if i close that new bookmark url window and again click on the bookmark button, a new window is opened which displays the template corresponding to the bookmarkk generated earlier (the report in its executed form), instaed of the bookmark url.
    Can anyone help me to correct this issue. At any time i click the bookmark button i want to get the bookmark url opened in the new window, instead of the template.
    Issue2: The bookmark is not at all working at particular times. It will show error message at the bottom the page. What I am  thinking is, this is because of the misalignment of the java code when you sava the WAD report. The java code is so sensitive that it gets realigned each time you save the WAD report. But sometimes even without making any changes also it is not working.
    If anyone has any suggestion or inputs for solving these issues pleese help ASAP. The java code i used is given below.
    function createBookmark()
    var bwUrl="<SAP_BW_URL CMD='BOOKMARK'>";
    child1=window.open(bwUrl,'win1','width=1,height=1,alwaysLowered=0');
    window.focus();
    //Ensure that BW completed generation of the bookmark url.
    now = new Date();
    startTime = now.getTime();
    delayTime = 3000;
    //Set timeout to 3 seconds
    waitTime = startTime;
    //check if the bookmark url is ready and timeout after the specified time (delayTime).
    while (waitTime<(startTime+delayTime))
    now = new Date();
    waitTime = now.getTime();
    //BW identifies a bookmark using BOOKMARK_ID. The presence of this string
    //in the url is used to identify creation of the bookmark. If bookmark
    //is created on the server, proceed to the next step.
    if (child1.location.href.indexOf("BOOKMARK_ID") >0) 
    break;
    bookmark_url = escape(child1.location.href);
    bookmark_url = bookmark_url.replace(/%3A/g, ":");
    bookmark_url = bookmark_url.replace(/%3F/g, "?");
    bookmark_url = bookmark_url.replace(/%26/g, "&");
    bookmark_url = bookmark_url.replace(/%3D/g, "=");
    var base_url = window.location+"";
    var base_index = base_url.indexOf("?");
    base_index = base_index + 1;
    var book_link = base_url.substring(0,base_index);
    if (book_link.indexOf("sapdbi")!=-1)
    book_link = "http://dep.xxx.com/sso/index.jsp?target=BW&";
    if (book_link.indexOf("sapqbia1")!=-1)
    book_link = "http://qep.xxx.com/sso/index.jsp?target=BW&";
    if (book_link.indexOf("sapqbia2")!=-1)
    book_link = "http://qep.xxx.com/sso/index.jsp?target=BW&";
    if (book_link.indexOf("sappbia1")!=-1)
    book_link = "https://portal.xxx.com/sso/index.jsp?target=BW&";
    if (book_link.indexOf("sappbia2")!=-1)
    book_link = "https://portal.xxx.com/sso/index.jsp?target=BW&";
    if (book_link.indexOf("sapqbi")!=-1)
    book_link = "http://qep.xxx.com/sso/index.jsp?target=BW&";
    if (book_link.indexOf("sappbi")!=-1)
    book_link = "https://portal.xxx.com/sso/index.jsp?target=BW&";
    var book_index = bookmark_url.indexOf("?");
    book_index =   book_index +   1; 
    var book_length = bookmark_url.length;
    var temp_link= bookmark_url.substring(book_index,book_length);
    portal_bwUrl = book_link+temp_link;
    child1.close();
    // The below two lines are not necessary, it is left for reference.
    // https://portal.xxx.com/sso/index.jsp?target=BW&SAP-               //LANGUAGE=EN&language=EN&cmd=LDOC&TEMPLATE_ID=IPUWT_FRAME
    bookmark_window=window.open("",'_blank','width=1000px,height=30px,status=0');
    bookmark_window.moveTo(50,500);
    var body_tag = '<body leftmargin=3 topmargin=3 bgcolor=#cad4e3 class=&amp;SAPBEXTbsBdyEdg&amp;>';
    var body_text ='<p><font face=Arial size=2>
    This bookmark can be copied and pasted to Internet Explorer-Favourites, mail or other documents:
    </p>';
    bookmark_window.document.write('<title name="SAP_BW_TITLE_!IID_171">Bookmark</title>',body_text, body_tag, portal_bwUrl, '</body>');
    Thanks in Advance.

    Hi Danny
    Thanks for the update
    Hi Danny
      Thanks for the update.
      I can't find any code in the attachment.Its a Web Page.
      Rightclick on webpage and View Source
      Then i can find Code.
      Still it is not working
    Issues: Which object i have to replace with the URL in the code
    Value = 'Weekly'
    or
    fun(WEEKLY REPORT)
    and
    when i paste that code in the XHTML tab of template and tried to save it,The scripted is changed
    Please update how to proceed
    Thanks

  • PL/SQL with GOTOXY function

    Hi all
    new to PL/SQL wonder got anyway to create gotoxy function like C
    thkx in adv

    PL/SQL is a procedural language. It does not use GO TO or other navigational tricks. It uses FUNCTION and PROCEDURE to build repeatable code units; and FOR...LOOP, WHILE...LOOP, IF...ELSIF...ELSE...END IF and (in 9i) CASE to control logic flow.
    This link will take you to a helpful page for beginners some of us have set up. This is maintained by volunteers and not by Oracle. It contains links to commonly-asked PL/SQL questions. More pertinent in your case, it also links to the Oracle online documentation. I suggest you read the PL/SQL Application Developer's Guide before you go any further.
    Re: How to attach a java bean in forms6i
    Good luck, APC

  • Incorrect values with AGO function

    Hi,
    I am trying to fix a problem where my AGO function is producing close but not 100% correct values.
    I have:
    Fact Table (pk is by date, employee, and measure keys)
    Dim Date Table (only date, month, quarter, year - very simple) Month and quarter are just numbers (not identified by year)
    Dim Emp Table
    I have a logical dimension hierarchy for Dim Date: Total > Year > Quarter > Month > Date
    In my Logical Fact table, I have a SUM column for the measure. My AGO column is just AGO(Measure (SUM), Dim Date.Month, 1)
    For my report, I have tried a few things.
    If I just use the Month column from my Date table, the AGO numbers are way off. If I do MONTH(Date) instead, the AGO numbers are close, and even accurate most of the time, but sometimes they will be a little bit off, by only 1 or 2 usually.
    I'm having the hardest time trying to figure this out, but one thing I'm suspicious of is the Date table - should Month and Quarter be like 2008-01, 2008-02, instead of just 01, 02?

    It would come as no surprise to me if the datetime dim is incorrect. I have been cleaning up someone else's mess.
    The date dim is just this:
    desc date_dim;
    Name                           Null     Type                                                                                                                                                                                         
    DATE_KEY                       NOT NULL NUMBER(8)                                                                                                                                                                                    
    D_YEAR                         NOT NULL NUMBER(4)                                                                                                                                                                                    
    D_MON                          NOT NULL NUMBER(2)                                                                                                                                                                                    
    D_DAY                          NOT NULL NUMBER(2)                                                                                                                                                                                    
    DATE_VALUE                     NOT NULL DATE                                                                                                                                                                                         
    D_QUARTER                      NOT NULL NUMBER(1)                                                                                                                                                                                    
    6 rows selectedFor today's date:
    DATE_KEY               D_YEAR                 D_MON                  D_DAY                  DATE_VALUE                D_QUARTER             
    20090417               2009                   4                      17                     17-APR-09                 2                     
    1 rows selectedI tried making the logical columns for D_YEAR||D_MON and D_YEAR||D_QUARTER, and added them as non-drillable chronological keys in my hierarchy, but still getting the same results.
    Any ideas?
    Edited by: KevinC_VA on Apr 17, 2009 2:40 PM

  • Count(*) function in select statement having group by condition

    Hi
    I would like to use count(*) in select statement having group by clause. say for example there is a state with a number of cities listed. I would like to get the count of cities for each state.
    the sql stement is grouped by state and it is joined with 5 more tables.
    Thanks
    ps: ignore the previous post

    Assuming there is one record per city per state, then
    SELECT state,count(*)
    FROM state_tbl
    GROUP BY stateWill get one record per state with the number of cities in each state. If you want to join that result set to other tables you need to either create a view with that statement or use an in-line view viz.
    SELECT c.cust_name,c.state,s.num_cities
    FROM customers c,
         (SELECT state,count(*) num_cities
          FROM state_tbl
          GROUP BY state) s
    WHERE c.state = s.stateTTFN
    John

Maybe you are looking for