Sql tuning using rank function

Hi,
Can someone help me in writing the below qry using rank() function?
DELETE FROM stc_calllog_ext a
WHERE a.stc_save_status = 'CT'
AND ROWID IN (SELECT a.ROWID
FROM stc_calllog_ext a, calllog_ext b
WHERE a.prod_line_code= b.prod_line_code
AND a.brand_code = b.brand_code
AND a.model_number = b.model_number
AND a.stc_save_status != b.stc_save_status
AND trunc(a.stc_start_time) = trunc(b.stc_start_time)
AND a.stc_start_time BETWEEN TRUNC(SYSDATE-8) AND TRUNC(SYSDATE)
AND a.call_taker_userid = b.call_taker_userid
AND a.cons_telephone_no =b.cons_telephone_no
)

With the information you have provided, I've come up with the following.
SELECT A.ACCOUNT_NO, A.PAYMENT_TYPE, A.INSTALLMENT_TYPE, A.DATE_CHANGE
FROM
    (SELECT account_no, payment_type, installment_type, date_change,
            LEAD( (payment_type), 1)
                 over (partition by account_no order by account_no, DATE_CHANGE)  LEAD_PAY,
            LEAD( (installment_type), 1)
                 over (partition by account_no order by account_no, DATE_CHANGE)  LEAD_INST
      from T_ACCNTS ) A
WHERE A.PAYMENT_TYPE <> NVL(A.LEAD_PAY,99)
   OR A.INSTALLMENT_TYPE <> NVL(A.LEAD_INST,99)
ORDER BY 1, 4;

Similar Messages

  • Error using Rank function in Answers

    Hi All,
    Am trying to generate a report in Answers which lists Top Accounts with Revenue.
    I Ranked the Revenue field and it is returning me correct values. ( Rank(account.revenue) )
    But, when I try to filter on this field and restrict the rows which shows only top 10 Accounts, it is returning the following error:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1792, message: ORA-01792: maximum number of columns in a table or view is 1000 at OCI call OCIStmtExecute. [nQSError: 17010] SQL statement preparation failed. (HY000)
    Can any one help me on this.
    Thanks in Advance,
    Imtiaz.

    Hi Joe,
    This is the Physical query generated when I use Rank function and the report is fine.
    select distinct D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7,
    D1.c8 as c8,
    D1.c9 as c9,
    D1.c10 as c10,
    D1.c11 as c11,
    D1.c12 as c12,
    D1.c13 as c13,
    D1.c14 as c14,
    D1.c15 as c15
    from
    (select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7,
    D1.c8 as c8,
    D1.c9 as c9,
    D1.c10 as c10,
    D1.c11 as c11,
    D1.c12 as c12,
    D1.c13 as c13,
    D1.c14 as c14,
    D1.c15 as c15
    from
    (select Case when D1.c1 is not null then Rank() OVER ( ORDER BY D1.c1 DESC NULLS LAST ) end as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c1 as c4,
    D1.c4 as c5,
    D1.c5 as c6,
    D1.c6 as c7,
    D1.c7 as c8,
    D1.c8 as c9,
    D1.c9 as c10,
    D1.c10 as c11,
    D1.c11 as c12,
    D1.c12 as c13,
    D1.c13 as c14,
    D1.c14 as c15,
    ROW_NUMBER() OVER (PARTITION BY D1.c1, D1.c2, D1.c3, D1.c4, D1.c5, D1.c6, D1.c7, D1.c8, D1.c9, D1.c10, D1.c11, D1.c12, D1.c13, D1.c14 ORDER BY D1.c1 ASC, D1.c2 ASC, D1.c3 ASC, D1.c4 ASC, D1.c5 ASC, D1.c6 ASC, D1.c7 ASC, D1.c8 ASC, D1.c9 ASC, D1.c10 ASC, D1.c11 ASC, D1.c12 ASC, D1.c13 ASC, D1.c14 ASC) as c16
    from
    (select distinct T690.SUM_REVN_AMT as c1,
    T690.NAME as c2,
    T2216.NAME as c3,
    T690.X_PETROFAC_REVN as c4,
    T690.SUM_WIN_PROB as c5,
    T690.X_PERCENT_GET as c6,
    T690.SUM_WIN_PROB * T690.X_PERCENT_GET / nullif( 100, 0) as c7,
    T690.X_EC_PRIORITY as c8,
    T19028.LOGIN as c9,
    T690.X_COUNTRY as c10,
    T690.X_REGION as c11,
    T18311.NAME as c12,
    T18641.NAME as c13,
    T18238.NAME as c14
    from
    SIEBEL.S_BU T18238 left outer join (
    SIEBEL.S_USER T19028 left outer join (
    SIEBEL.S_OPTY T690 left outer join SIEBEL.S_STG T2216 On T690.CURR_STG_ID = T2216.ROW_ID) left outer join SIEBEL.S_ORG_EXT T1189 On T690.PR_DEPT_OU_ID = T1189.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18311 /* Competitor */ On T690.PR_CMPT_OU_ID = T18311.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18641 /* Partner */ On T690.PR_PRTNR_ID = T18641.ROW_ID) left outer join SIEBEL.S_POSTN T19114 On T690.PR_POSTN_ID = T19114.PAR_ROW_ID) left outer join SIEBEL.S_OPTY_BU T18280 On T690.ROW_ID = T18280.OPTY_ID) left outer join SIEBEL.S_OPTY_X T19415 On T690.ROW_ID = T19415.PAR_ROW_ID) On T19028.PAR_ROW_ID = T19114.PR_EMP_ID) On T18238.ROW_ID = T18280.BU_ID
    ) D1
    ) D1
    where ( D1.c16 = 1 )
    ) D1
    order by c1 desc
    But When I apply Filter on this Rank column then it gives me the error. THis is the Physical query for that
    select distinct Case when D1.c1 is not null then Rank() OVER ( ORDER BY D1.c1 DESC NULLS LAST ) end as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c1 as c4,
    D1.c4 as c5,
    D1.c5 as c6,
    D1.c6 as c7,
    D1.c7 as c8,
    D1.c8 as c9,
    D1.c9 as c10,
    D1.c10 as c11,
    D1.c11 as c12,
    D1.c12 as c13,
    D1.c13 as c14,
    D1.c14 as c15
    from
    (select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7,
    D1.c8 as c8,
    D1.c9 as c9,
    D1.c10 as c10,
    D1.c11 as c11,
    D1.c12 as c12,
    D1.c13 as c13,
    D1.c14 as c14
    from
    (select T690.SUM_REVN_AMT as c1,
    T690.NAME as c2,
    T2216.NAME as c3,
    T690.X_PETROFAC_REVN as c4,
    T690.SUM_WIN_PROB as c5,
    T690.X_PERCENT_GET as c6,
    T690.SUM_WIN_PROB * T690.X_PERCENT_GET / nullif( 100, 0) as c7,
    T690.X_EC_PRIORITY as c8,
    T19028.LOGIN as c9,
    T690.X_COUNTRY as c10,
    T690.X_REGION as c11,
    T18311.NAME as c12,
    T18641.NAME as c13,
    T18238.NAME as c14,
    Case when T690.SUM_REVN_AMT is not null then Rank() OVER ( ORDER BY T690.SUM_REVN_AMT DESC NULLS LAST ) end as c15
    from
    SIEBEL.S_BU T18238 left outer join (
    SIEBEL.S_USER T19028 left outer join (
    SIEBEL.S_OPTY T690 left outer join SIEBEL.S_STG T2216 On T690.CURR_STG_ID = T2216.ROW_ID) left outer join SIEBEL.S_ORG_EXT T1189 On T690.PR_DEPT_OU_ID = T1189.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18311 /* Competitor */ On T690.PR_CMPT_OU_ID = T18311.ROW_ID) left outer join SIEBEL.S_ORG_EXT T18641 /* Partner */ On T690.PR_PRTNR_ID = T18641.ROW_ID) left outer join SIEBEL.S_POSTN T19114 On T690.PR_POSTN_ID = T19114.PAR_ROW_ID) left outer join SIEBEL.S_OPTY_BU T18280 On T690.ROW_ID = T18280.OPTY_ID) left outer join SIEBEL.S_OPTY_X T19415 On T690.ROW_ID = T19415.PAR_ROW_ID) On T19028.PAR_ROW_ID = T19114.PR_EMP_ID) On T18238.ROW_ID = T18280.BU_ID
    ) D1
    where ( D1.c15 <= 10 )
    ) D1
    order by c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15
    Thanks,
    Imtiaz

  • How to use "Rank" function  in Oracle?

    I need to display Top 15 records by using rank function.
    Here is my query...I need to pull top 15 FAQ's using the below query.. How can I use RANK function to display the Top 15 FAQ"s in the list.
    Select  distinct SUb1.FAQ,Sub1.FAQ_Hits,GU.display_Name_FMLS as displayname,ev.ParentLinkrecordid,ev.userid from User GU
    Join Event ev
    ON LOWER (ev.userid) IN (LOWER (GU.lanid), LOWER (Gu.racfid))
    Join (Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID from Event ev
    Join SubjectMatter sm
    ON (TO_CHAR (sm.smrecordid) = ev.eventdetail1) AND ev.eventdetail1 IS NOT NULL AND sm.smtype = 1
    Where (Upper(ev.eventsubtype) in (Upper('FAQ'),Upper('OPENFAQ')))
    AND TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= TO_DATE ('20100601', 'yyyymmdd')
    and TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= TO_DATE ('20100831', 'yyyymmdd')
    Group by sm.stem,ev.Parentlinkrecordid
    order by FAQ )sub1
    ON Sub1.Topic_ID = ev.ParentLinkrecordid)

    A few bits that I noticed in the query ...
    in (Upper('FAQ'),Upper('OPENFAQ'))1) Do you really a upper for a string which is already in upper case.
    Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID2) Do you need a distinct when you are using a GROUP function viz. SUM ?
    You rank query is as follows, I am not very good at the ANSI style JOIN so changed it slightly ... :-)
    Also notice the usage rank function in the "sub1" query.
    select distinct sub1.faq,
                    sub1.faq_hits,
                    gu.display_name_fmls as displayname,
                    ev.parentlinkrecordid,
                    ev.userid
    from user gu, event ev,
      (select rank() over (order by sum(ev.eventresults) desc) rnk,
              sum(ev.eventresults) as faq_hits,
              sm.stem as faq,         
              ev.parentlinkrecordid as topic_id
         from event ev, subjectmatter sm
        where (to_char(sm.smrecordid) = ev.eventdetail1)
          and ev.eventdetail1 is not null
          and sm.smtype = 1
          AND upper(ev.eventsubtype) in ('FAQ', 'OPENFAQ')
          and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= to_date('20100601', 'yyyymmdd')
          and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= to_date('20100831', 'yyyymmdd')
        group by sm.stem, ev.parentlinkrecordid
        order by faq) sub1
    where lower(ev.userid) in (lower(gu.lanid), lower(gu.racfid))
      and sub1.topic_id = ev.parentlinkrecordid)
      and sub1.rnk <= 15;Like mentioned above, some sample data would have helped.

  • How to use RANK function ?

    Hello everyone,
    here is the query I run in sql developer using RANKFunction.
    SELECT Empno, Ename, Job, Mgr, Hiredate, Sal
    FROM
    (SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,
    *RANK*() OVER
    (ORDER BY SAL Desc NULLS LAST) AS Emp_Rank
    FROM Emp
    ORDER BY SAL Desc NULLS LAST)
    WHERE Emp_Rank < 6;How I can use this query in my report in obiee or is there any replacement of RANK() function in obiee so that I can use that to get my same above result.
    Thanks

    Kuldip wrote:
    Thanks, you are absolutely correct. However, By doing this I am getting my output as whic I was not expecting.
    Students Marks Rank
    student1 95 1
    student2 95 1
    student3 93 3
    student4 93 3
    student5 91 5
    The output should be as instead
    Students Marks Rank
    student1 95 1
    student2 95 1
    student3 93 2
    student4 93 2
    student5 91 3
    Can It be done like this ?
    Thanks.
    Edited by: Kuldip on Mar 15, 2012 11:51 PMHi Boss,
    I think you copied the above scenario from this site..
    http://oracle-bi.siebelunleashed.com/articles/rank-and-dense-rank-functionsobiee/
    Then why asking how to do this? Are you testing us? Doesn't that site say how to achieve this?

  • SQL query using MAX function

    I am trying to only display the records where the 'date_entered' is the most recent date per case number.
    SELECT distinct c.case_number, u.email,c.assigneddate_chart,
    --m.date_entered,
    max(m.date_entered)as last_date_entered,
    trunc(sysdate)-trunc(c.assigneddate_chart)days_late,
    trunc(sysdate)-trunc(m.date_entered)addl_days_late
    from chart c, chart_user_roles u,comments m
    where
    (c.case_status IN ('Open','Pending')) and
    c.case_number=m.case_number
    group by c.case_number,
    u.email,c.assigneddate_chart,m.date_enteredRight now, this is the output im am getting.
    Output:
    CASE_NUMBER------EMAIL---------ASSIGNEDDATE_CHART---LAST_DATE_ENTERED---DAYS_LATE--ADDL_DAYS_LATE
    [email protected]----06-NOV-09-----------------31--------------------11
    [email protected]----10-NOV-09-----------------31---------------------7
    [email protected]----06-NOV-09-----------------31--------------------11
    [email protected]----06-NOV-09-----------------31--------------------11
    [email protected]----06-NOV-09-----------------31--------------------11
    [email protected]----03-NOV-09-----------------34--------------------14
    I am wanting to achieve this output:
    Therefore, based on the data below, the only records that i am wanting to display are:
    [email protected]----10-NOV-09-----------------31---------------------7
    [email protected]----03-NOV-09-----------------34--------------------14
    Thanks
    Deanna

    Is there a reason that you have a DISTINCT in your query? It always makes me nervous to see that where it's not clearly necessary because it frequently means that a developer is missing a join condition and is using the DISTINCT to mask that fact.
    On to the meat of your question, though, is there a potential for ties? If so, how do you want to handle that-- do you want two rows for that case, do you want to break the tie using some other column, do you want to pick an arbitrary row? If you want to pick an arbitrary row
    SELECT case_number, email, assignedDate_chart, last_date_entered, days_late, addl_days_late
      FROM (
        SELECT a.*, row_number() over (partition by case_number order by date_entered) rn
          FROM (<<your query>>) a
    WHERE rn = 1If you want to do something else, just adjust the analytic function and use RANK or add a tie-breaker to the ORDER BY.
    Justin

  • SQL Tuning using Enterprise manager in oracle 10g

    Hi,
    In oracle 10g you have the enterprise manager which can be used to tune sql statements using the SQL Tuning ADvisor and SQL access advisor.
    I believe in oracle 10g the process of SQL Tuning is slightly easier using the Enterprise Manager ...so if some one could explain me that process...
    Again thanking you in advance
    regds
    Manoj Gokhale

    Hi Manoj,
    Didn't you already start two other threads about this same question the SQL forum?
    How do i do the SQL Statement tuning
    Enterprise Manager - sql tuning advisor , Access advisor for SQL Tuning

  • Compile forms error because using rank function

    Hi,
    Oracle Form 9i don't known rank function in my SQL statement. When compile forms, it alerts err message: "Encountered the symbol "(" when expecting one ..."
    code:
    select * from (
    select group_id, acct_no, acct_desc, rank() over(order by acct_no desc) rank_no from customer
    where group_id='002'
    ) where rank_no< 10000
    Help me ASAP.
    Many thank,
    Bum.

    Where is INTO clause ? Plz provide the actual code you are writing.
    I think this type of queries not supported in Forms 9i.....try forms 10g or above.

  • Sql Tuning using OEM and Logon triggers

    OEM = 10.2.0.4/Agent 10.2.0.4
    Target = 10.2.0.3 Db
    We have several db users that have session level adjustments made by use of logon triggers. When OEM is used to review one of those session's performance and sql tuning opportunities - are the logon triggers and the session level settings taken into consideration? Another way to ask is if the suggested changes from the sql profiler are making decisions based on the user's session level settings?
    Thank you in advance.
    -abe

    Your logon triggers affect the new sessions. When you monitor with OEM, it is no affect on OEM's activity. Hoping that, your logon trigger did not affect the user which OEM uses to connect to repository DB.

  • Filtering maximum rank using rank function ?

    Hi ,
    I have two table emp_changes(empno(number),operation_time(timestamp),operation(varchar))
    and another table emp_metadata(tablename(varchar),max_time(timestamp))(it has got one row )
    using this query :
        select empno,operation,RANK() OVER (PARTITION BY empno ORDER BY operation_time) "time" from emp_changes
    where empno in (select empno from emp_changes where operation_time BETWEEN (select max_time from emp_metadata) AND sysdate)I am getting this output:
    EMPNO OPERATION time
    8009 INSERT 1
    8009 UPDATE 2
    8009 DELETE 3
    8010 INSERT 1
    8013 INSERT 1
    9001 UPDATE 1
    9001 DELETE 2
    can anyone please tell me how to achive this like ,I want to view only distinct empno,operation with max rank in time like:
    EMPNO OPERATION
    8009 DELETE
    9001 DELETE
    Thanks ,
    Deekay

    Hi, Deekay,
    Analytic functions (inlcude RANK) are computed after the WHERE cluase is appled.
    To use the results of an analytic function in a WHERE clause, first compute the analytic function in a sub-query, then use the value in the WHERE clause of a super-query, like this:
    select     empno
    ,     operation
    from      (     -- Begin sub-query to compute time_rank
                select  empno
                ,       operation
                ,       RANK () OVER ( PARTITION BY  empno
                                               ORDER BY      operation_time     DESC
                                  )           AS time_rank
                from    emp_changes
                where   operation_time     BETWEEN (
                                                    select  max_time
                                      from    emp_metadata
                             AND      sysdate
         )       -- End sub-query to compute time_rank
    WHERE     time_rank     = 1
    ;If you'd like to post CREATE TABLE and INSERT statements for your data, then I could test this.
    While it is possible to see which is the highest number returned by RANK, it is easier to see which is the lowest number; the lowest number is always 1. That's why I used DESCending order.

  • Top 'n' using rank () function

    Hi...
    I'm using BO XI 3.0. In my report I need  a user to enter TOP 'n' (n=5,10,20,50,100).
    For example:
    Caller No           No of Calls
    23467891              10
    67698089              35
    22377868              17
    76378467              10
    76374678              20
    89978978               6
    87786777              11
    I already create dimension object for Caller No and measure object for No of Calls in universe.
    So I use a rank filter in edit query but it doesn't work.
    I also create another measure object in universe name =ranking
    rank(No_of_Calls) over(partition by (Caller No) order by (No_of_Calls)).. but it's not work...
    So can anybody help me....thanks

    Hi,
    Following information might be helpful in resolving the issue.
    General Syntax of Ranking :
    Rank( measure; (dimensions); [Top|Bottom])
    Here is the work flow with an example :- (use efashion universe )
    1) Create a webi report selecting objects quarter, year, sales revenue and create a cross tab
    2) While creating a cross tab, use the Object Year in columns and object Quarter for rows.
    3)Define a variable Var1 = Rank ([Sales Revenue] ; [Quarter]; [Year]) ForEach ([Year])
    4) Insert a blank column next to year in the cross tab.
    5) Drag and drop the variable Var1 in the new blank column inserted next to Object Year..
    You will now find that you have ranking for the years 2001, 2002, 2003 being reflected
    independently.
    Regards,
    Sarbhjeet Kaur

  • How to use rank function in obiee rpd using evalute..

    i created a logical column:
    EVALUATE('RANK() OVER (PARTITION BY %1,%2)' AS DOUBLE PRECISION , Composites.Composites_Fact.MEMBER_LOCKED_BASE_RETURN, Composites.Composites_Fact.COMP_ID)
    please provide some solution

    There is a known bug with EVALUATE when returning numbers. When I has the same problem Oracle Metalink has adviced to use CAST on the end result of the EVALUATE and return it as a FLOAT datatype.
    CAST(EVALUATE('my_function(%1)', logical_table.ROWID) AS FLOAT)

  • Using Rank function in mdx

    I have the following data in my cube
    Prod ID  Account ID     Measure
    1            10                    20
    2            10                    20
    2            20                    10
    Now I want an mdx query which would show an aggregation against the Account ID 10 as 20 only and not 40 as the Account ID is the same which means the desired output has to be something like
    Account ID  Measure
    10                20
    20                10
    Note that Prod ID and Account ID are from different Dimensions.
    Please let me know how do I do this in MDX. Any help is greatly appreciated!!

    Hi N
    Another option is to use the Generate function and just take the last Prod Id for each Account.  Your MDX will look something like
    select non empty 
    {[Measures].[MyMeasure]
    } on 0, 
    non empty  
    generate([Account ID].[Account ID].[Account ID].members
    ,tail(nonempty([Prod ID].Prod ID].Prod ID]*[Account ID].[Account ID].currentmember,[Measures].[MyMeasure]),1))
    on 1
    from MyCube 
    Richard

  • SQL Query - Using Lag function

    Hi All,
    I need to select the previous and next record, when the value of column is changed for each account.
    My table structure is as follows:
    Account_No number(10)
    Payment_type number(5)
    Installment_Type number(5)
    Date_chage date
    Sample record:
    Account_No Payment_Type Installment_Type Date_change
    70539 ** 1 ** 2 ** 01-OCT-83
    70539 ** 1 ** 2 ** 03-FEB-01
    70539 ** 1 ** 2 ** 26-APR-02
    70539 ** 1 ** 1 ** 21-JUN-02
    70539 ** 1 ** 2 ** 12-JUL-02
    185562 ** 1 ** 2 ** 23-APR-02
    185562 ** 2 ** 2 ** 10-MAY-02
    In the above sample data, the value of instalment is changed on 21-jun-02 and 12-jul-02 for the account 70539. Also the value of Payment Type is changed on 23-apr-02 for the account 185562.
    So, my output should be like this.
    Account_No Payment_Type Installment_Type Date_change
    70539 ** 1 ** 2 ** 26-APR-02
    70539 ** 1 ** 1 ** 21-JUN-02
    70539 ** 1 ** 2 ** 12-JUL-02
    185562 ** 1 ** 2 ** 23-APR-02
    185562 ** 2 ** 2 ** 10-MAY-02
    I tried with lag function, but I couldnt succeed. Im using oracle 8.1.6 Version.
    Can anyone help me to achieve this?
    ** To distinguish the value for each coulmn.
    Thanks and regards,
    Vijay R.

    With the information you have provided, I've come up with the following.
    SELECT A.ACCOUNT_NO, A.PAYMENT_TYPE, A.INSTALLMENT_TYPE, A.DATE_CHANGE
    FROM
        (SELECT account_no, payment_type, installment_type, date_change,
                LEAD( (payment_type), 1)
                     over (partition by account_no order by account_no, DATE_CHANGE)  LEAD_PAY,
                LEAD( (installment_type), 1)
                     over (partition by account_no order by account_no, DATE_CHANGE)  LEAD_INST
          from T_ACCNTS ) A
    WHERE A.PAYMENT_TYPE <> NVL(A.LEAD_PAY,99)
       OR A.INSTALLMENT_TYPE <> NVL(A.LEAD_INST,99)
    ORDER BY 1, 4;

  • Wrong order in pivot table using Rank function

    Hi Gurus,
    I have the following query:
    SELECT Periods."Year" saw_0, Periods."Month" saw_1, SalesFacts.Dollars saw_2, RANK(SalesFacts.Dollars BY Periods."Year") saw_3
    FROM SupplierSales ORDER BY saw_0, saw_3
    In table view the order is correct.
    However in pivot table for 1998 (year) the order is correct, for 1999 not!
    Ordering : 1. Year, 2. RANK
    Page: Year, Rows : Months
    Measures : Dollars and RANK
    ( I tried to put the RANK into Rows section, the result is same )
    What is the reason of this strange behavior?
    Thanks
    Laszlo

    Try Sort Column and Row properties given in pivot Table Chart...
    Maybe your problem will resolve

  • Help with simple sql statement usiing Rank function..

    Hello I have very important question..this is how i have a dataset...
    This is the Log Table 
    And the actual Table holds the current value.   12345
    Current Table 
    12345    575 232 4567
    Log Table Values
    Objectid InvalidatedTime
    PhoneArea
    Phoneno Rank
    12345   2014-04-23
    570          
    822-4438      0  
    3
    12345   2014-04-28
    NULL
    658-7789      0
    2
    12345   2014-05-09
    578        
    658-8521      0 
    1
    As you can see on 23 they invlalidated the areacode and phone no and changed it to .. 578 658-8521 but on 04-28 they just changed the phone no and not the area code.. 
    I want the result set to be like this
    Date Fromvalue   
    ToValue  
    2014-04-23 
    570-822-4438      
      578 658-7789
    2014-04-28 578 658-7789 
    578 658-8521
    2014-05-09  578 658-8521
    575 
    232 4567
     I have tried this code.. 
    select 
    --'Home Phone',
    --tt.invalidationtime ,
    --Case when 
    -- tt.*,tt_prev.* --,
    'Home Phone' as PropertyName,
    tt.invalidationtime,
    case when tt.rank1 = 1 then tt.phoneareacode+'-'+tt.phoneno
    when tt.rank1 <> 1 then Isnull(tt.phoneareacode,tt_prev.phoneareacode)+'-'+ isnull(tt.phoneno,tt_prev.phoneno)
    end as FromAddress,
    case when tt.rank1 = 1 then Haddress.phoneareacode+'-'+HAddress.phoneno
    when tt.rank1 <> 1 then Isnull(tt_prev.phoneareacode,tt.phoneareacode)+'-'+isnull(tt_prev.phoneno,tt.phoneno)
    end as ToPhone
    from
     #Phone_Final  tt
    left join  #Phone_Final tt_prev on tt_prev.objectid = tt.objectid and tt.rank1-11 = tt_prev.rank1
    inner join (select * from Soarian_Clin_Prd_1.dbo.Haddress   where PP_id = 2346   and Addresstype = 0) Haddress
    Can you please tell me what is wrong here.. 

    should be this I reckon
    ;With CTE
    AS
    SELECT ROW_NUMBER() OVER (PARTITION BY ObjectID ORDER BY InvalidatedTime) AS Seq, *
    FROM
    SELECT ObjectID,InvalidatedTime,PhoneArea,Phoneno,Rank
    FROM LogTable
    UNION ALL
    SELECT ObjectID, GETDATE(),PhoneArea,Phoneno,NULL
    FROM Current
    )t
    SELECT c1.InvalidatedDate AS [Date],
    COALESCE(c1.PhoneArea,c2.PhoneArea,'') + c1.Phoneno AS FromValue,
    COALESCE(c2.PhoneArea,c1.PhoneArea,'') + c2.Phoneno AS ToValue
    FROM CTE c1
    INNER JOIN CTE c2
    ON c2.Objectid = c1.Objectid
    AND c2.Seq = c1.Seq + 1
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • How do i delete music off my ipod on my iphone?

    I have lot's of duplicate song's on my ipod and need to get them off so that i can have more space on my iphone....anyone know if this is possible and if so how do i do it??

  • Downloading new photos - iPhoto doesn't work after upgrading to Yosemite

    Hello, Since I upgraded to Yosemite, iPhoto has stooped working after downloading photos from my Sd card. Some picutres downloaded are black while some others are ok, but in any case I have to restart my iMac because every apps running can't be used

  • Search for users and non-ASCII characters

    I am having a little issue with the "Accounts - Find Users" functionality. The search breaks on what I assume is non-ASCII characters (we use the following three up here in Denmark: �, �, �). To be precise, I have a user with the first name "J�rgen".

  • Errors installing web service to use dreamweaver extension

    Portal Version: 10g OS/Vers. Where Portal is Installed:: Linux AS 2.1 Errors installing web service to use dreamweaver extension Recently I download the dreamweaver extension for portal, but when I try to install it several errors are raised... in th

  • Can I grant permission to write in specific attributes using security groups

    Hi I Created GPO that write the computer name in the one of the user attribute "comment attribute " when  he logged on then i went to OU and grant self delegate permissions to allow the users of that OU to write on "comment attribute but this did not