Need to re write as a one query

Hi,
I have a below two queries and i need re write as same query.I'm passing test session id's to second query as of now.In second query i have minimum 5 recods for 1 test session id.finally I'm converting rows as a column from second query based on roster_domain_name column(see the finally o/p).could you some on help.advance thanks.
1st query
SELECT DISTINCT a.test_session_id test_session_id, address,
                TO_CHAR (birth_date, 'yyyy-MM-dd') AS birth_date,
                branching_profile_name, city, email, exnum, first_name,
                home_phone, institution_id_display, last_name, middle_name,
                site_id_display, state_name, student_id,
                TO_CHAR (test_session_date,
                         'yyyy-MM-dd') AS test_session_date, zip
           FROM vuestudenttestsessioninfo a, test_session_detail b
          WHERE EXISTS (
                   SELECT td.test_detail_id
                     FROM test_detail td
                    WHERE domain_map_id IS NOT NULL
                      AND b.test_detail_id = td.test_detail_id
                      AND domain_map_id IN (27604,27605,27606,27607))
            AND site_id IN ('8904')
           AND TRUNC (test_session_date) BETWEEN TO_DATE ('11/24/2009',
                                                           'MM/DD/YYYY'
                                              AND TO_DATE ('12/4/2009',
                                                           'MM/DD/YYYY'
            AND a.test_session_status_id IN (3, 4)
            AND a.test_session_id = b.test_session_id
       ORDER BY address1st query o/p like below
TEST_SESSION_ID     ADDRESS     BIRTH_DATE     BRANCHING_PROFILE_NAME     CITY     EMAIL     EXNUM     FIRST_NAME     HOME_PHONE     INSTITUTION_ID_DISPLAY     LAST_NAME     MIDDLE_NAME     SITE_ID_DISPLAY     STATE_NAME     STUDENT_ID     TEST_SESSION_DATE     ZIP
SELECT a.test_session_id,c.roster_domain_name,to_char(a.score),a.sem FROM
      test_session_detail a,test_session b ,test_detail c
      WHERE a.test_session_id = b.test_session_id
      AND c.test_detail_id = a.test_detail_id
      AND exists (
      select td.test_detail_id
      from test_detail td
      where domain_map_id is not  null
      and c.test_detail_id =td.test_detail_id
      and domain_map_id in('303','306','305','304'))
      AND b.test_session_id in (getting session ids from 1st query)
      AND domain_group_id NOT IN (
      SELECT domain_group_id
      FROM test_session_detail a,test_session b
      WHERE a.test_session_id = b.test_session_id
      AND a.domain_group_id is not null
      AND b.test_session_status_id = 4
      AND a.test_session_status_id <> 3
      AND b.test_session_id IN (getting session ids from 1st query))
2nd query o/p
TEST_SESSION_ID     ROSTER_DOMAIN_NAME     TO_CHAR(A.SCORE)     SEM
final o/p
Address     Birth Date     Branching Profile     City     Email     Exnum     First Name     Home Phone     Inst ID     Last Name     Middle Initial     Site ID     State/ Province     Student ID     Test Date     Zip Code     AR - Integers and Fractions     AR - Decimal Numbers     AR - Percent     AR - Estim, Ordering, Numb. Sense     AR - Word Problems

Hi ,
Version *10.1.0.2.0*
Business rule is:
I have two scenarios 1) can use first query getting result
2) can use both queries getting result.
In second scenario i'm facing problem with regarding taking more time due to executing two queries one after one.
because i'm getting test session id's from first query executing and displaying results from both quires .Now i have thought to merge both queries as a one query.I think it's possible with in line view quires(2nd query).Pls help
And DDL part i'm using 1 view and reaming tables.here those scripts.
VIEW vuestudenttestsessioninfo
Name                                      Null?    Type                       
STUDENT_ID                                NOT NULL VARCHAR2(50)               
FIRST_NAME                                NOT NULL VARCHAR2(50)               
MIDDLE_NAME                                        VARCHAR2(50)               
LAST_NAME                                 NOT NULL VARCHAR2(50)               
ADDRESS                                            VARCHAR2(201)              
CITY                                               VARCHAR2(30)               
STATE_PROVINCE_COUNTRY                             VARCHAR2(30)               
ZIP                                                VARCHAR2(20)               
EMAIL                                              VARCHAR2(100)              
HOME_PHONE                                         VARCHAR2(20)               
CELL_PHONE                                         VARCHAR2(20)               
BIRTH_DATE                                         DATE                       
STUDENT_ID_PK                             NOT NULL NUMBER                     
EXNUM                                     NOT NULL NUMBER(9,)                 
TEST_SESSION_DATE                                  DATE                       
COMPLETION_DATE                                    DATE                       
TEST_SESSION_ID                           NOT NULL NUMBER(9,)                 
INSTITUTION_ID                            NOT NULL NUMBER                     
SITE_ID                                   NOT NULL NUMBER                     
BRANCHING_PROFILE_ID                      NOT NULL NUMBER(10,)                
TEST_SESSION_STATUS_ID                    NOT NULL NUMBER(10,)                
INSTITUTION_ID_DISPLAY                             VARCHAR2(10)               
SITE_ID_DISPLAY                                    VARCHAR2(10)               
STATE_NAME                                         VARCHAR2(30)               
BRANCHING_PROFILE_NAME                             VARCHAR2(100)              
SITE_NAME                                 NOT NULL VARCHAR2(200)              
ADDRESS_2                                          VARCHAR2(100)              
ADDRESS_1                                          VARCHAR2(100)
SQL> desc test_session  
Name                                      Null?    Type
TEST_SESSION_ID                           NOT NULL NUMBER(9)
INSTITUTION_ID                            NOT NULL NUMBER
STUDENT_ID_PK                             NOT NULL NUMBER(9)
BRANCHING_PROFILE_ID                      NOT NULL NUMBER(10)
TEST_SESSION_STATUS_ID                    NOT NULL NUMBER(10)
TEST_SESSION_DATE                                  DATE
ACCESSED_TIMES                                     NUMBER(9)
COMPLETION_DATE                                    DATE
DURATION                                           NUMBER(10)
CREATED_ON                                         DATE
MODIFIED_ON                                        DATE
CREATED_BY                                         NUMBER
MODIFIED_BY                                        NUMBER
IS_RESUMED                                         CHAR(1)
SQL> desc test_session_detail
Name                                      Null?    Type
TEST_SESSION_DETAIL_ID                    NOT NULL NUMBER(9)
TEST_SESSION_ID                           NOT NULL NUMBER(9)
TEST_DETAIL_ID                            NOT NULL NUMBER(10)
TEST_SESSION_STATUS_ID                             NUMBER
THETA                                              NUMBER
SCORE                                              NUMBER
PERCENTILE                                         NUMBER
SEM                                                NUMBER
TEST_START_DATE                                    DATE
TEST_END_DATE                                      DATE
TEST_DURATION                                      NUMBER
CREATED_ON                                         DATE
MODIFIED_ON                                        DATE
CREATED_BY                                         NUMBER
MODIFIED_BY                                        NUMBER
TEST_SEED                                          VARCHAR2(15)
TEST_ALIAS                                         VARCHAR2(30)
COMPANION_FORM                                     CHAR(1)
DURATION_START_DATE                                TIMESTAMP(6)
DURATION_END_DATE                                  TIMESTAMP(6)
DOMAIN_GROUP_ID                                    NUMBER
TIMER_LIMIT                                        VARCHAR2(100)
SQL> desc test_detail
Name                                      Null?    Type
TEST_DETAIL_ID                            NOT NULL NUMBER(10)
TEST_TYPE_ID                              NOT NULL NUMBER(10)
OPERATIONAL_POOL_ID                                NUMBER(10)
FIELD_TEST_POOL_ID                                 NUMBER(10)
INSTITUTION_ID                            NOT NULL NUMBER
TEST_NAME                                 NOT NULL VARCHAR2(500)
TEST_ALIAS                                         VARCHAR2(30)
DESCRIPTION                                        VARCHAR2(100)
OPERATIONAL_TEST_LENGTH                            NUMBER
ACTIVE_STATUS                                      CHAR(1)
DELETE_STATUS                                      CHAR(1)
FIELD_TEST_ITEM                                    VARCHAR2(1)
FIELD_TEST_LENGTH                                  NUMBER
IS_DIR_SAMPLE                                      CHAR(1)
DIR_SAMPLE_PATH                                    VARCHAR2(1000)
CREATED_ON                                         DATE
MODIFIED_ON                                        DATE
CREATED_BY                                         NUMBER
MODIFIED_BY                                        NUMBER
FORM_NAME                                          VARCHAR2(10)
DOMAIN_MAP_ID                                      NUMBER(9)
DOMAIN_SEQUENCE                                    NUMBER(9)
ROSTER_DOMAIN_NAME                                 VARCHAR2(100)

Similar Messages

  • Need to pull ranked item from one query into new query

    Hi,
    I have a parent query in which I assign a rank to characteristic values based on a key figure, in dollars. I need to pull the top 4 items from that parent query into 4 seperate child queries (i.e. child query 1 is written based on ranked item 1, child query 2 is written based on ranked item 2, etc.) Does anyone have any ideas how to achieve this?
    Thanks
    CM

    Hi,
    I have a parent query in which I assign a rank to characteristic values based on a key figure, in dollars. I need to pull the top 4 items from that parent query into 4 seperate child queries (i.e. child query 1 is written based on ranked item 1, child query 2 is written based on ranked item 2, etc.) Does anyone have any ideas how to achieve this?
    Thanks
    CM

  • Need to use the results of one query as an input to another query

    Hi, I have one sql query in my XML file, that returns more than one values for a column.
    and i want to use this output one by one as an input to the second query to retrive the data from the second query.
    Could please someone tell me if its possible in XML Publisher?
    If possible, please share the syntax to do the same
    For eg:
    Query 1:
    Select data1, data2 from query1 ; -- output data1 and data2
    want to use data1 and data2 one by one in the below query
    Query 2:
    select * from abc where name_id= data1/data2;
    Thanks and Regards
    Madhu

    Make sure your cursor declarations are in your declare section, not between the begin and end statements.

  • Need to merge 3 quiries as one query

    Hi All,
    Please help me on below issue.
    Below 3 queries are written in a 3 procedures and all 3 quiries are accessing same table and slight difference only is there.Please help to merge 3 queries to 1 query for hitting database only once.
    *** are displaying instead of C U M in below posting thred ,i don't know why it is.Please where ever 3 starts are there assume that is C U M1st one
    INSERT INTO WASTE_PREF_DOW
            (PERIOD_KEY,
            CONSUMER_KEY,
            PREFDOW,
            FIN_SCOR_DOW,
            GRANULAR
    SELECT STARTPERIOD PERIOD_KEY,CONSUMER_KEY,DOW_KEY  PREFDOW,nvl(FIN_SCOR_DOW,-1),GRANULAR1 GRANULAR FROM
    SELECT CONSUMER_KEY,DOW_KEY,FIN_SCOR_DOW,
    ROW_NUMBER() OVER ( PARTITION BY CONSUMER_KEY ORDER BY FIN_SCOR_DOW DESC,DOW_KEY ) RNO
    FROM
    SELECT CONSUMER_KEY,DOW_KEY,SUM(SCORE_SERVICE_WEIGHT) FIN_SCOR_DOW FROM
    SELECT DOW_KEY,CONSUMER_KEY,SERVICE_KEY,DUR,TRAN,VOLU,TOT_DUR, CUM_DUR,TOT_TRAN,CUM_TRAN,TOT_VOL,CUM_VOL,SCORE_DUR,SCORE_TRAN,SCORE_VOL,
    1*NVL(SCORE_DUR,0)+1*NVL(SCORE_TRAN,0)+1*NVL(SCORE_VOL,0) TOT_SCOR ,
    CASE
    WHEN SERVICE_KEY= 0 THEN
    1*SCORE_DUR
    WHEN SERVICE_KEY IN ('1','3') THEN
    1*SCORE_TRAN
    WHEN SERVICE_KEY  = 2 THEN
    1*SCORE_VOL
    END SCORE_SERVICE_WEIGHT FROM
    select DOW_KEY,consumer_key,service_key,sumDUR dur,SUMTRAN tran,sumVOL volu,
    tot_dur,cum_dur,tot_tran,cum_tran,tot_vol,cum_vol,
    case
    when tot_dur > 0 then
    cum_dur*100/tot_dur
    end score_dur,
    case
    when tot_tran > 0 then
    cum_tran*100/tot_tran
    end score_tran,
    case
    when tot_vol > 0 then
    cum_vol*100/tot_vol
    end  score_vol
    from
    SELECT CONSUMER_KEY,SERVICE_KEY,DOW_KEY,SUMDUR,SUMTRAN,SUMVOL,SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_DUR,
    SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY) CUM_DUR,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_TRAN,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMTRAN,DOW_KEY) CUM_TRAN,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_VOL,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMVOL,DOW_KEY) CUM_VOL
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    FROM
    SELECT CONSUMER_KEY,SERVICE_KEY, to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D')) DOW_KEY,
    sum(SUM_OF_DURATION) sumdur,SUM(NO_OF_TRANSACTIONS) sumtran,sum(SUM_OF_VOLUME) sumvol
    --ROW_NUMBER () OVER (ORDER BY CONSUMER_KEY) RNO
    FROM SERVICE_FACTS_BY_DAY
    WHERE DATE_KEY BETWEEN STARTPERIOD AND ENDPERIOD
    group by CONSUMER_KEY,SERVICE_KEY,to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D'))
    ORDER BY CONSUMER_KEY,SERVICE_KEY,to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D'))
    GROUP BY CONSUMER_KEY,DOW_KEY
    WHERE RNO=1;2nd one
    INSERT INTO WASTE_PREF_POW
            (PERIOD_KEY,
            CONSUMER_KEY,
            PREFPOW,
            FIN_SCOR_POW,
            GRANULAR
    SELECT STARTPERIOD PERIOD_KEY,CONSUMER_KEY,POW_KEY  PREFPOW,nvl(FIN_SCOR_POW,-1),GRANULAR1 GRANULAR FROM
    SELECT CONSUMER_KEY,POW_KEY,FIN_SCOR_POW,
    ROW_NUMBER() OVER ( PARTITION BY CONSUMER_KEY ORDER BY FIN_SCOR_POW DESC,POW_KEY ) RNO
    FROM
    SELECT CONSUMER_KEY,POW_KEY,SUM(SCORE_SERVICE_WEIGHT) FIN_SCOR_POW FROM
    SELECT POW_KEY,CONSUMER_KEY,SERVICE_KEY,DUR,TRAN,VOLU,TOT_DUR,CUM_DUR,TOT_TRAN,CUM_TRAN,TOT_VOL,CUM_VOL,SCORE_DUR,SCORE_TRAN,SCORE_VOL,
    1*NVL(SCORE_DUR,0)+1*NVL(SCORE_TRAN,0)+1*NVL(SCORE_VOL,0) TOT_SCOR ,
    CASE
    WHEN SERVICE_KEY= 0 THEN
    1*SCORE_DUR
    WHEN SERVICE_KEY IN ('1','3') THEN
    1*SCORE_TRAN
    WHEN SERVICE_KEY  = 2 THEN
    1*SCORE_VOL
    END SCORE_SERVICE_WEIGHT FROM
    select POW_KEY,consumer_key,service_key,sumDUR dur,SUMTRAN tran,sumVOL volu,
    tot_dur,cum_dur,tot_tran,cum_tran,tot_vol,cum_vol,
    case
    when tot_dur > 0 then
    cum_dur*100/tot_dur
    end score_dur,
    case
    when tot_tran > 0 then
    cum_tran*100/tot_tran
    end score_tran,
    case
    when tot_vol > 0 then
    cum_vol*100/tot_vol
    end  score_vol
    from
    SELECT CONSUMER_KEY,SERVICE_KEY,POW_KEY,SUMDUR,SUMTRAN,SUMVOL,SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_DUR,
    SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,POW_KEY) CUM_DUR,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_TRAN,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMTRAN,POW_KEY) CUM_TRAN,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_VOL,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMVOL,POW_KEY) CUM_VOL
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    FROM
    SELECT CONSUMER_KEY,SERVICE_KEY, DECODE (to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D')),6,0,7,0,1 ) POW_KEY,                                                                                            
    sum(SUM_OF_DURATION) sumdur,SUM(NO_OF_TRANSACTIONS) sumtran,sum(SUM_OF_VOLUME) sumvol
    --ROW_NUMBER () OVER (ORDER BY CONSUMER_KEY) RNO
    FROM SERVICE_FACTS_BY_DAY
    WHERE DATE_KEY BETWEEN STARTPERIOD AND ENDPERIOD
    group by CONSUMER_KEY,SERVICE_KEY,DECODE (to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D')),6,0,7,0,1)                                                                                             
    ORDER BY CONSUMER_KEY,SERVICE_KEY,DECODE (to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D')),6,0,7,0,1)                                                                                             
    GROUP BY CONSUMER_KEY,POW_KEY
    WHERE RNO=1;3rd one
    INSERT INTO WASTE_PREF_TOD
            (PERIOD_KEY,
            CONSUMER_KEY,
            PREFTOD,
            FIN_SCOR_TOD,
            GRANULAR
    SELECT STARTPERIOD PERIOD_KEY,CONSUMER_KEY,TOD_KEY  PREFTOD,nvl(FIN_SCOR_TOD,-1),GRANULAR1 GRANULAR FROM
    SELECT CONSUMER_KEY,TOD_KEY,FIN_SCOR_TOD,
    ROW_NUMBER() OVER ( PARTITION BY CONSUMER_KEY ORDER BY FIN_SCOR_TOD DESC,TOD_KEY ) RNO
    FROM
    SELECT CONSUMER_KEY,TOD_KEY,SUM(SCORE_SERVICE_WEIGHT) FIN_SCOR_TOD FROM
    SELECT TOD_KEY,CONSUMER_KEY,SERVICE_KEY,DUR,TRAN,VOLU,TOT_DUR,CUM_DUR,TOT_TRAN,CUM_TRAN,TOT_VOL,CUM_VOL,SCORE_DUR,SCORE_TRAN,SCORE_VOL,
    1*NVL(SCORE_DUR,0)+1*NVL(SCORE_TRAN,0)+1*NVL(SCORE_VOL,0) TOT_SCOR ,
    CASE
    WHEN SERVICE_KEY= 0 THEN
    1*SCORE_DUR
    WHEN SERVICE_KEY IN ('1','3') THEN
    1*SCORE_TRAN
    WHEN SERVICE_KEY  = 2 THEN
    1*SCORE_VOL
    END SCORE_SERVICE_WEIGHT FROM
    select TOD_KEY,consumer_key,service_key,sumDUR dur,SUMTRAN tran,sumVOL volu,
    tot_dur,cum_dur,tot_tran,cum_tran,tot_vol,cum_vol,
    case
    when tot_dur > 0 then
    cum_dur*100/tot_dur
    end score_dur,
    case
    when tot_tran > 0 then
    cum_tran*100/tot_tran
    end score_tran,
    case
    when tot_vol > 0 then
    cum_vol*100/tot_vol
    end  score_vol
    from
    SELECT CONSUMER_KEY,SERVICE_KEY,TOD_KEY,SUMDUR,SUMTRAN,SUMVOL,SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_DUR,
    SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,TOD_KEY) CUM_DUR,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_TRAN,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMTRAN,TOD_KEY) CUM_TRAN,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_VOL,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMVOL,TOD_KEY) CUM_VOL
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    FROM
    SELECT CONSUMER_KEY,SERVICE_KEY,TOD_KEY,
    sum(SUM_OF_DURATION) sumdur,SUM(NO_OF_TRANSACTIONS) sumtran,sum(SUM_OF_VOLUME) sumvol
    --ROW_NUMBER () OVER (ORDER BY CONSUMER_KEY) RNO
    FROM SERVICE_FACTS_BY_DAY
    WHERE DATE_KEY BETWEEN STARTPERIOD AND ENDPERIOD
    group by CONSUMER_KEY,SERVICE_KEY,TOD_KEY
    ORDER BY CONSUMER_KEY,SERVICE_KEY,TOD_KEY
    GROUP BY CONSUMER_KEY,TOD_KEY
    WHERE RNO=1;

    Might be like this (don't like the distinct operator)
    with
    all_sums as
    (select consumer_key,
            service_key,
            'd_' || to_char(date_key,'yyyymmdd','d') d_key,
            sum(sum_of_duration) over (partition by consumer_key,service_key,'d_' || to_char(date_key,'yyyymmdd','d') order by null) d_sumdur,
            sum(no_of_transactions) over (partition by consumer_key,service_key,'d_' || to_char(date_key,'yyyymmdd','d') order by null) d_sumtran,
            sum(sum_of_volume) over (partition by consumer_key,service_key,'d_' || to_char(date_key,'yyyymmdd','d') order by null) d_sumvol,
            'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1') p_key,
            sum(sum_of_duration) over (partition by consumer_key,service_key,'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1')
                                           order by null) p_sumdur,
            sum(no_of_transactions) over (partition by consumer_key,service_key,'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1')
                                              order by null) p_sumtran,
            sum(sum_of_volume) over (partition by consumer_key,service_key,'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1'),
                                         order by null) p_sumvol,
            't_' || tod_key t_key,
            sum(sum_of_duration) over (partition by consumer_key,service_key,'t_' || tod_key order by null) t_sumdur,
            sum(no_of_transactions) over (partition by consumer_key,service_key,'t_' || tod_key order by null) t_sumtran,
            sum(sum_of_volume) over (partition by consumer_key,service_key,'t_' || tod_key order by null) t_sumvol,
       from service_facts_by_day
      where date_key between startperiod and endperiod
    all_queries as
    (select distinct consumer_key,service_key,the_key,sumdur,sumtrans,sumvol
       from (select consumer_key,service_key,d_key the_key,d_sumdur sumdur,d_sumtrans sumtrans,d_sumvol sumvol
               from all_sums
             union all
             select consumer_key,service_key,p_key,p_sumdur,p_sumtrans,p_sumvol
               from all_sums
             union all
             select consumer_key,service_key,t_key,t_sumdur,t_sumtrans,t_sumvol
               from all_sums
    select startperiod,consumer_key,the_key,nvl(fin_scor_type,-1),granular1
      from (select consumer_key,
                   the_key,
                   fin_scor_type,
                   row_number() over (partition by consumer_key,the_key order by fin_scor_type desc,the_key) rno
              from (select consumer_key,the_key,sum(score_service_weight) fin_scor_type,the_key
                      from (select tod_key,consumer_key,service_key,the_key,
                                   case when service_key = 0
                                        then score_dur
                                        when service_key in (1,3)
                                        then score_tran
                                        when service_key = 2
                                        then score_vol
                                   end score_service_weight
                              from (select tod_key,consumer_key,service_key,the_key,
                                           case when tot_dur > 0
                                                then kum_dur * 100 / tot_dur
                                           end score_dur,
                                           case when tot_tran > 0
                                                then kum_tran * 100 / tot_tran
                                           end score_tran,
                                           case when tot_vol > 0
                                                then kum_vol * 100 / tot_vol
                                           end score_vol
                                      from (select consumer_key,service_key,key_type,the_key,
                                                   sum(sumdur) over (partition by consumer_key,service_key,the_key) tot_dur,
                                                   sum(sumdur) over (partition by consumer_key,service_key,the_key order by sumdur,the_key) kum_dur,
                                                   sum(sumtran) over (partition by consumer_key,service_key,the_key) tot_tran,
                                                   sum(sumtran) over (partition by consumer_key,service_key,the_key order by sumtran,the_key) kum_tran,
                                                   sum(sumvol) over (partition by consumer_key,service_key,the_key) tot_vol,
                                                   sum(sumvol) over (partition by consumer_key,service_key,the_key order by sumvol,the_key) kum_vol
                                              from (select consumer_key,service_key,the_key,sumdur,sumtran,sumvol
                                                      from all_queries
                                                     group by consumer_key,service_key,the_key
                     group by consumer_key,the_key
    where rno = 1Regards
    Etbin
    Edited by: Etbin on 6.6.2010 2:17
    got rid of distinct
    with
    all_sums as
    (select consumer_key,
            service_key,
            'd_' || to_char(date_key,'yyyymmdd','d') d_key,
            sum(sum_of_duration) over (partition by consumer_key,service_key,'d_' || to_char(date_key,'yyyymmdd','d') order by null) d_sumdur,
            sum(no_of_transactions) over (partition by consumer_key,service_key,'d_' || to_char(date_key,'yyyymmdd','d') order by null) d_sumtran,
            sum(sum_of_volume) over (partition by consumer_key,service_key,'d_' || to_char(date_key,'yyyymmdd','d') order by null) d_sumvol,
            'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1') p_key,
            sum(sum_of_duration) over (partition by consumer_key,service_key,'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1')
                                           order by null) p_sumdur,
            sum(no_of_transactions) over (partition by consumer_key,service_key,'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1')
                                              order by null) p_sumtran,
            sum(sum_of_volume) over (partition by consumer_key,service_key,'p_' || decode(to_char(date_key,'yyyymmdd','d'),'6','0','7','0','1'),
                                         order by null) p_sumvol,
            't_' || tod_key t_key,
            sum(sum_of_duration) over (partition by consumer_key,service_key,'t_' || tod_key order by null) t_sumdur,
            sum(no_of_transactions) over (partition by consumer_key,service_key,'t_' || tod_key order by null) t_sumtran,
            sum(sum_of_volume) over (partition by consumer_key,service_key,'t_' || tod_key order by null) t_sumvol,
            row_number() over (partition by consumer_key,service_key) the_row
       from service_facts_by_day
      where date_key between startperiod and endperiod
    all_queries as
    (select consumer_key,service_key,d_key the_key,d_sumdur sumdur,d_sumtrans sumtrans,d_sumvol sumvol
       from all_sums
      where the_row = 1
    union all
    select consumer_key,service_key,p_key,p_sumdur,p_sumtrans,p_sumvol
       from all_sums
      where the_row = 1
    union all
    select consumer_key,service_key,t_key,t_sumdur,t_sumtrans,t_sumvol
       from all_sums
      where the_row = 1
    select startperiod,consumer_key,the_key,nvl(fin_scor_type,-1),granular1
      from (select consumer_key,
                   the_key,
                   fin_scor_type,
                   row_number() over (partition by consumer_key,the_key order by fin_scor_type desc,the_key) rno
              from (select consumer_key,the_key,sum(score_service_weight) fin_scor_type,the_key
                      from (select tod_key,consumer_key,service_key,the_key,
                                   case when service_key = 0
                                        then score_dur
                                        when service_key in (1,3)
                                        then score_tran
                                        when service_key = 2
                                        then score_vol
                                   end score_service_weight
                              from (select tod_key,consumer_key,service_key,the_key,
                                           case when tot_dur > 0
                                                then kum_dur * 100 / tot_dur
                                           end score_dur,
                                           case when tot_tran > 0
                                                then kum_tran * 100 / tot_tran
                                           end score_tran,
                                           case when tot_vol > 0
                                                then kum_vol * 100 / tot_vol
                                           end score_vol
                                      from (select consumer_key,service_key,key_type,the_key,
                                                   sum(sumdur) over (partition by consumer_key,service_key,the_key) tot_dur,
                                                   sum(sumdur) over (partition by consumer_key,service_key,the_key order by sumdur,the_key) kum_dur,
                                                   sum(sumtran) over (partition by consumer_key,service_key,the_key) tot_tran,
                                                   sum(sumtran) over (partition by consumer_key,service_key,the_key order by sumtran,the_key) kum_tran,
                                                   sum(sumvol) over (partition by consumer_key,service_key,the_key) tot_vol,
                                                   sum(sumvol) over (partition by consumer_key,service_key,the_key order by sumvol,the_key) kum_vol
                                              from (select consumer_key,service_key,the_key,sumdur,sumtran,sumvol
                                                      from all_queries
                                                     group by consumer_key,service_key,the_key
                     group by consumer_key,the_key
    where rno = 1

  • Grouped and non-grouped SELECT in one query: help!

    look first at: Wrong result when I use CASE on this forum. Here I wanted to get the user who created and the user who solved a problem (Lets call it Validation Error from now on (VE)).
    The thing is: I already have a query who returns me lots of information about a VE.
    The query in the previous thread returned me additional info about that VE (that is the creating_user and the solving_user). The 1st query is no group select, but the second is! Still, I need to combine those two in one query.
    1st query:
    select ve.seq,
         max((case vah.action when 'C' then vah.ur_code else null end)) created,
         max((case vah.action when 'S' then vah.ur_code else null end)) solved
    from validation_errors ve
    left outer join ver_action_histories vah
    on (ve.seq = vah.ver_seq AND ve.log_date = vah.ver_log_date)
    where ve.seq = 12860687
    group by ve.seq;Result:
    seq       | created | solved
    12860687    Bob       Bobdont mind the "where"-clause, it is just to make the query go faster
    what I do is: I join the VE with the ver_action_histories table which contains the users and what action they performed on a VE.
    Now I just want to add that information to the results of an other query which also returns lots of information about a VE.
    2nd query:
    select ve.seq "VE seq", mh.seq "Counter seq",
              ve.log_date, ve.solve_date, ve.solved Status, ve.failure_code, ve.mde_code,
              mh.meter_type,
              iv.mr_type, iv.mr_reason,
              ih.mmr_seq
    from validation_errors ve
    inner join meter_histories mh
    on (ve.mhy_seq = mh.seq)
    left outer join index_values iv
    on (ve.mhy_seq = iv.mhy_seq AND ve.log_date =iv.timestamp)
    left outer join index_histories ih
    on (ve.mhy_seq = ih.ive_mhy_seq)
    where ve.seq = 8653936
    and sysdate >= mh.start_date
    and sysdate < mh.end_date;dont mind the "where" and "and"-clauses ... I hope the result of this query will simplify things ...
    Result:
    seq        |   counter seq | log_date | solved_date | status    | failure_code | ...
    12860687       4568          1-jan-06   2-jan-06      Solved      ABCNow the actual question: Is it possible to combine those queries in one query? I just want the results of the first query (creating_user and solving_user) to be added as columns to the second result. Performance is very important. Please tell me that its possible?
    Wanted Result:
    seq        |   counter seq | log_date | solved_date | status    | failure_code | created  | solved  | ...
    12860687       4568          1-jan-06   2-jan-06      Solved      ABC            Bob        BobIf anything I explained is unclear, please tell so I can try to explain it in an easier way.

    Try an in line view:
    select *
    from
    ( <your first query goes here > ) a
    , ( <your second query goes here > ) b
    where a.seq = b.seq

  • How can i write two ?DDL in one query

    how can i write two ?DDL statment in one query?

    Issuing two DDL statements requires two edxecutions. Getting around it is possible by creating a procedure that issues the two DDL statements. But they would still have to be issues one at a time, but you would only have to write one statement to invoke it.

  • I need to print one query result as a single row

    Hi,
    I need to print one query result as a single row ,which gives more than one value (of subinventories)and also i would like to print the quantity of that particular subinventory at particular place.Please suggest how can i do this in the report builder?

    Actually I need to print inventory report with subinventory break up.For that all subinventories of category code AB are taken as single row.Based on that subinventory value Quantity must be printed at that particular place.
    For ex
    Quantity
    Item no Description Subinventory Code AB_Abc AB_Def AB_ghi
    1 ***** 12 9
    2 ****** 8 5
    like that.I am waiting for the reply.Plz its some how urgent.
    Thank you,

  • I need two query in one report (two detail section in one query)

    Hi master sorry for again distribute
    Sir I need two query in one report
    Because I need two detail section in my one report
    Such as
    Master
    Vno=9088989
    Detail          1
    =
    =
    ==
    =
    Total                     99999
    Detail          2
    =
    =
    ==
    =
    Total                     33333
    Sir how I get this type of report
    Please give me idea
    Thanking you
    Aamir

    I want to see the report as follow.
    d_name: CPU-1
    date: -----------
    Software installed:
    sw_id, software, version, serial_no, sw_type
    (list of softwares attached, can be more then one)
    Hardware attached:
    hw_id, hardware, specification (same like software list, it will contain hardware list attached to specific device),
    Please if you can help me that how will i make a query for this.
    Thanks and Regards
    Maz

  • One Query need to tune

    I have one query below to tune.
    Here one table USER_RETAILER_MAP and its column BELONGS_TO having value only 'Y' and 'N'.
    Created bitmap index but i am not getting any cost difference.
    Please share your idea ,how to tune and what process should follow.
    SQL> explain plan for
    2 SELECT a.user_id,
    3 a.user_nm,
    4 2 AS max_level
    5 FROM gss_user a
    6 WHERE a.user_id NOT IN (SELECT user_id
    7 FROM user_retailer_map
    8 WHERE retailer_id IN (SELECT b.retailer_id
    9 FROM user_retailer_map b,
    10 retailer c
    11 WHERE
    12 b.retailer_id = c.retailer_id
    13 AND b.user_id = :a
    14 AND c.status = 'ACTIVE'
    15 AND b.managed_by = 'Y')
    16 AND belongs_to = 'Y')
    17 AND Upper(a.status) = 'ACTIVE'
    18 AND a.user_id IN (SELECT user_id
    19 FROM user_hierarchy
    20 WHERE parent_user_id = :b)
    21 AND a.gmac_dealer_user_flg = 'D'
    22 ORDER BY Upper(user_nm) ASC
    23 ;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1 | 91 | 65 |
    | 1 | SORT ORDER BY | | 1 | 91 | 65 |
    |* 2 | HASH JOIN ANTI | | 1 | 91 | 63 |
    | 3 | NESTED LOOPS SEMI | | 7 | 504 | 9 |
    |* 4 | TABLE ACCESS FULL | GSS_USER | 33 | 1254 | 9 |
    |* 5 | INDEX UNIQUE SCAN | XPKGSS_USER_HIERARCHY | 7 | 238 | |
    | 6 | VIEW | VW_NSO_1 | 212 | 4028 | 53 |
    |* 7 | HASH JOIN | | 212 | 15476 | 53 |
    |* 8 | HASH JOIN | | 15 | 675 | 9 |
    | 9 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 15 | 420 | 4 |
    |* 10 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 15 | | 1 |
    |* 11 | INDEX FAST FULL SCAN | INDX_RETAILE | 1594 | 27098 | 4 |
    |* 12 | TABLE ACCESS FULL | USER_RETAILER_MAP | 22885 | 625K| 43 |
    Predicate Information (identified by operation id):
    2 - access("A"."USER_ID"="VW_NSO_1"."$nso_col_1")
    4 - filter(UPPER("A"."STATUS")='ACTIVE' AND "A"."GMAC_DEALER_USER_FLG"='D')
    5 - access("A"."USER_ID"="USER_HIERARCHY"."USER_ID" AND "USER_HIERARCHY"."PARENT_USER
    _ID"=:Z)
    7 - access("USER_RETAILER_MAP"."RETAILER_ID"="B"."RETAILER_ID")
    8 - access("B"."RETAILER_ID"="C"."RETAILER_ID")
    10 - access("B"."USER_ID"=:Z AND "B"."MANAGED_BY"='Y')
    11 - filter("C"."STATUS"='ACTIVE')
    12 - filter("USER_RETAILER_MAP"."BELONGS_TO"='Y')
    }

    How to post a SQL statement tuning request...
    HOW TO: Post a SQL statement tuning request - template posting

  • Read from 2 tables, write only to one. Simple, but impossible??

    I've been messing about with various annotations for quite a while now, and I can't seem to figure out how to accomplish this seemingly simple task. I'm hoping somebody could explain to me the probably very obvious and simple mistake that I am making.
    I realize that question would otherwise point to problems in my database design and persistence strategy, but I can't seem to read from 2 tables, and write to only one. I have an entity bean that refers mainly to one table, but needs just one column of information from another table. It should not attempt to alter the secondary table, just join on it to get the one field it needs. So far, I've got the following:
    @Entity
    @Table(name = "ventureprofile")
    @SecondaryTable(name = "venture",
                    pkJoinColumns = @PrimaryKeyJoinColumn(name="ventureid"))
    @NamedQueries( {
            @NamedQuery(name = "Ventureprofile.findByVentureprofileid", query = "SELECT v FROM Ventureprofile v WHERE v.ventureprofileid = :ventureprofileid"),
            @NamedQuery(name = "Ventureprofile.findByVentureid", query = "SELECT v FROM Ventureprofile v WHERE v.ventureid = :ventureid"),
            @NamedQuery(name = "Ventureprofile.findByVenturesummary", query = "SELECT v FROM Ventureprofile v WHERE v.venturesummary = :venturesummary"),
            @NamedQuery(name = "Ventureprofile.findByLogoimagelocation", query = "SELECT v FROM Ventureprofile v WHERE v.logoimagelocation = :logoimagelocation"),
            @NamedQuery(name = "Ventureprofile.findByVisible", query = "SELECT v FROM Ventureprofile v WHERE v.visible = :visible ORDER BY v.venturename")
    public class Ventureprofile implements Serializable {
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO, generator="Ventureprofile.ventureprofileid.seq")
        @SequenceGenerator(name="Ventureprofile.ventureprofileid.seq", sequenceName="ventureprofile_ventureprofileid_seq", allocationSize=1) 
        @Column(name = "ventureprofileid", nullable = false)
        private BigInteger ventureprofileid;      
        @Column(name = "ventureid", table="ventureprofile", nullable = false)
        private Long ventureid;
        @Column(name = "venturesummary")
        private String venturesummary;
        @Column(name = "logoimagelocation")
        private String logoimagelocation;
        @Column(name = "visible", nullable = false)
        private boolean visible;  
        @Column(table = "venture", name = "venturename", nullable=false, insertable=false, updatable=false)
        private String venturename;
    //... The extra column of data is "venturename", the tables are related by the column "ventureid". I contest, that since I have specified for read/write access no fields mapped to the 'venture' table (I specified with 'table=' any ambiguous columns), and described the table relationship via my @PrimaryKeyJoinColumn annotation, that toplink should not try to persist anything to the 'venture' table. However, I am getting the following exception:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: org.postgresql.util.PSQLException: ERROR: null value in column "venturename" violates not-null constraint
    Error Code: 0
    Call: INSERT INTO venture (ventureid) VALUES (?)
            bind => [220]
    Query: InsertObjectQuery(VCMarkWeb.db.entity.Ventureprofile[ventureprofileid=220])
            at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:311)
    ...It seems pretty clear that toplink is trying to insert an empty row into the secondary table, and barfing since it is inserting no values, including those constrained to be nonnull. Anyway...I hope it's clear what's going on here, and perhaps somebody knows the right way to do this. Thanks fot your help!

    Tom and Cornelius,
    Thank you both for your ideas. This what I think I will do:
    1) Drive up to OWC (fortunately they are only about 15 miles away from where I live) and get a bigger HD and some more RAM.
    2) Copy the OS9 applications on the existing HD to a thumb drive.
    3) Install the new hard drive and memory
    4) Install OSX TIger and 9.2.2
    5) Maybe do the 4.1.8 firmware update also, maybe.
    6) Look around for a Superdrive and if I can get one for a good price, I'll do it otherwise I'll just use USB thumb drives if I need to copy something off the PB.
    One thing that I was fighting with the other day was that when I had the yoyo power supply plugged in and attached when the PB was in the kitchen, the batteries would not charge although the yoyo was outputting +24 VDC.
    I move everything to the garage, where I originally fixed the yoyo power supply, plug it in out there and the batteries started charging!!! Scratching my head...then I check the voltage between the metal barrel (with the Vsensing resistor attached between the metal shell and the ground wire) of power supply plug and the +24 VDC wire and there is 22 to 23 VDC with the batteries being charged. In the kitchen when they were not being charged, it was about 1.0 VDC. So I rotate the plug a little bit and the batteries start charging. Rotate it more and the batteries don't charge. Something else to do when I have spare time.
    Anyway, thanks for the help and suggestions.
    John

  • About give from one query to other the same value of a variable

    Hi Gurus,
    my problem is About give from one query to other the same value of a variable, i have a wad with a view, and this wad has some bottoms in javascript to go to anothers wad with charts, the problem is when i ran the query one, i put a value = calyear:2008 (Obligatory Variable), but when i click the bottom to go to the other query with the same variable, he ask me again a value,
    i want write a value just one time, and the others wad can recieve the first value that i put when the wad opened.
    i really need it , thanks !

    Hello Jorge,
    What you need here is Replacement path variable. Check out this link for more details:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/bd/589b3c494d8e15e10000000a114084/content.htm
    In the second query where you need the value (calyear:2008 from first query) create a Variable for calyear of type Replacement path, in Replacement tab you can select either query or variable by which it has to replaced. In your case, it has to be variable from the first query.
    Do let me know if this works. If this does not work I suggest you to use Web APIs to replace the variable values using Web APIs. Check out the details:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/29/4d15422ecce02ce10000000a1550b0/frameset.htm
    Hope this helps.
    Regards,
    Srini

  • Can you check for data in one table or another but not both in one query?

    I have a situation where I need to link two tables together but the data may be in another (archive) table or different records are in both but I want the latest record from either table:
    ACCOUNT
    AccountID     Name   
    123               John Doe
    124               Jane Donaldson           
    125               Harold Douglas    
    MARKETER_ACCOUNT
    Key     AccountID     Marketer    StartDate     EndDate
    1001     123               10526          8/3/2008     9/27/2009
    1017     123               10987          9/28/2009     12/31/4712    (high date ~ which means currently with this marketer)
    1023     124               10541          12/03/2010     12/31/4712
    ARCHIVE
    Key     AccountID     Marketer    StartDate     EndDate
    1015     124               10526          8/3/2008     12/02/2010
    1033     125               10987         01/01/2011     01/31/2012  
    So my query needs to return the following:
    123     John Doe                        10526     8/3/2008     9/27/2009
    124     Jane Donaldson             10541     12/03/2010     12/31/4712     (this is the later of the two records for this account between archive and marketer_account tables)
    125     Harold Douglas               10987          01/01/2011     01/31/2012     (he is only in archive, so get this record)
    I'm unsure how to proceed in one query.  Note that I am reading in possibly multiple accounts at a time and returning a collection back to .net
    open CURSOR_ACCT
              select AccountID
              from
                     ACCOUNT A,
                     MARKETER_ACCOUNT M,
                     ARCHIVE R
               where A.AccountID = nvl((select max(M.EndDate) from Marketer_account M2
                                                    where M2.AccountID = A.AccountID),
                                                      (select max(R.EndDate) from Archive R2
                                                    where R2.AccountID = A.AccountID)
                   and upper(A.Name) like parameter || '%'
    <can you do a NVL like this?   probably not...   I want to be able to get the MAX record for that account off the MarketerACcount table OR the max record for that account off the Archive table, but not both>
    (parameter could be "DO", so I return all names starting with DO...)

    if I understand your description I would assume that for John Dow we would expect the second row from marketer_account  ("high date ~ which means currently with this marketer"). Here is a solution with analytic functions:
    drop table account;
    drop table marketer_account;
    drop table marketer_account_archive;
    create table account (
        id number
      , name varchar2(20)
    insert into account values (123, 'John Doe');
    insert into account values (124, 'Jane Donaldson');
    insert into account values (125, 'Harold Douglas');
    create table marketer_account (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account values (1001, 123, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('27.09.2009', 'dd.mm.yyyy'));
    insert into marketer_account values (1017, 123, 10987, to_date('28.09.2009', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    insert into marketer_account values (1023, 124, 10541, to_date('03.12.2010', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    create table marketer_account_archive (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account_archive values (1015, 124, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('02.12.2010', 'dd.mm.yyyy'));
    insert into marketer_account_archive values (1033, 125, 10987, to_date('01.01.2011', 'dd.mm.yyyy'), to_date('31.01.2012', 'dd.mm.yyyy'));
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account_archive;
    with
    basedata as (
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account_archive
    basedata_with_max_intervals as (
    select key, AccountId, MktKey, FromDt, ToDate
         , row_number() over(partition by AccountId order by FromDt desc) FromDt_Rank
      from basedata
    filtered_basedata as (
    select key, AccountId, MktKey, FromDt, ToDate from basedata_with_max_intervals where FromDt_Rank = 1
    select a.id
         , a.name
         , b.MktKey
         , b.FromDt
         , b.ToDate
      from account a
      join filtered_basedata b
        on (a.id = b.AccountId)
    ID NAME                     MKTKEY FROMDT     TODATE
    123 John Doe                  10987 28.09.2009 31.12.4712
    124 Jane Donaldson            10541 03.12.2010 31.12.4712
    125 Harold Douglas            10987 01.01.2011 31.01.2012
    If your tables are big it could be necessary to do the filtering (according to your condition) in an early step (the first CTE).
    Regards
    Martin

  • Crystal Report Many to One Query Config error when using DataSet.ReadXML me

    When I build a dataset with this method numerous relations are automatically created. I then map these fields onto crystal reports with ADO.net data connection. However when I run the report the following error occurs:
    CrystalDecisions.CrystalReports.Engine.InternalException: Cannot determine the queries necessary to get data for this report.Details:
    This query cannot be performed. The link order requires many to one query configuration, which is not supported. Please rearrange the links.
    If I remove the links (relations) i get duplicate data on the report. Is there any way to resolve this or a patch for the error?

    Hello, Mervin;
    Since you are using ADO.NET dataset, is it possible to get all of the fields you need in one SQL Query outside of Crystal Reports?
    If that is possible, you can use that dataset to create an XML or XSD file to use as the structure for your report.
    VB
    'Using the full path to the .xml file, include the schema
    dataSet.WriteXml("C:\temp\test.xml", XmlWriteMode.WriteSchema)
    or
    dataSet.WriteXmlSchema("c:\temp\testXML.xsd")
    Now create a new report with the ADO.NET(XML) connection and point to either the XML or XSD you created. XML is useful because you can view data in the report designer for final formatting of the report.
    Now there is only one datasource and no linking is required in Crystal Reports. That should resolve the one to many issue.
    Another useful tool is to group on the many and place all the fields normally in the detail section into that group header. Suppress the Detail and Group footer sections. The Group Header will now look like a Detail section and each distinct value will only appear once. You can group on one field or a combination (using a formula field) to get the results you need. Test this to be sure you do not miss anything you want to see.
    Elaine

  • Running a  BEx report with more than one query in Background

    I am having a workbook with 2 queries .This workbook needs to be executed at a particular time every day and then save this file to a application server location .
    The file name has to dynamic, as everday a new file has to be created with some date stamp.
    Please let me know the steps/ ideas to achieve this

    Sudhakar,
    are you sure that it has to b a workbook ? running queries independently can be done .. am not sure if a workbook can be scheduled to run...
    One alternative is to use APD - have the queries run and populate two ODS and then have these ODS in a multiprovider and have one query output for the same - seems to be a very longworkaround...
    Another option is to have the queries executed in an ABAP programme and then have the results in an internal table and push both the result sets into an excel sheet ad save it in the application server.
    For reading queries in ABAP there is a functionmodule for the same .. something like RSDRI_INFOPROV_READ .. I am not too sure of the name but there is a function module for sure..
    Hope it helps..
    Arun
    Assign points if it helps..

  • BI 7.0 : Refresh of only one Query with VBA in  a MultiQueryWorkbook

    Does anyone know how to refresh only one query with VBA in a Workbook with several queries on different sheets?

    Hello together,
    thanks for your replies.
    In the backend EHP1 is installed and I think we don't need an extra update for the frontend. But in the VBA code of the frontend the code didn't changed.
    Our BEX Analyzer Addin version is:  7100.4.1100.34
    BEx Patch Level is: Support Package 11 Revision 1606
    The VBA code is:
    Public Function SAPBEXrefresh(allQueries As Boolean, Optional atCell As Range) As Integer
    'In the 7.0 Analyzer, ALL the items in the workbook can be refreshed, but refreshing
    'a query individually is not supported
    On Error Resume Next
      extErrorBegin ("3.x API SAPBEXRefresh called")
      If allQueries = True Then
        Common.MenuRefresh
        SAPBEXrefresh = 0
      Else
        SAPBEXrefresh = 700
        p_extErrorText = "With 7.0, this API is partly supported to refresh ALL items in the workbook, NOT an individual Query"
      End If
      extErrorEnd
    End Function
    As you can see a individually query with this VBA code is still not supported.
    Does anyone know how to change this code or if we need a special update?
    Daniel
    Edited by: Marc Schlipphak on Jan 19, 2010 7:35 PM

Maybe you are looking for