SQL Query to get the desired result

Can someone give the SQL to get this output.
input is like this in table.
cola     colb     fromdate     todate
1     100     1/5/2010     1/9/2010
1     101     1/10/2010     1/25/2010
1     102     1/26/2010     12/31/2900
2     201     3/1/2011     3/10/2011
2     202     3/11/2011     12/31/2900
3     301     1/5/2010     1/9/2010
3     302     1/10/2010     1/25/2010
3     303     1/26/2010     1/28/2010
3     304     1/29/2010     12/31/2900
I want to get the output like this.
cola     colb     fromdate     todate
1     100     1/5/2010     1/9/2010
2     201     3/1/2011     3/10/2011
3     301     1/5/2010     1/9/2010
More info:
I want to get the rows where fromdate is the min(fromdate) from each cola's unique values i.e. 1,2,3
Please let me know the SQL.
Thanks.
[email protected]

This way!!!
with data(cola, colb, st_dt, ed_dt) as
select 1,     100,     to_date('01/05/2010', 'MM/DD/YYYY'),     to_date('01/09/2010', 'MM/DD/YYYY') from dual union all
select 1,     101,  to_date('01/10/2010', 'MM/DD/YYYY'),     to_date('01/25/2010', 'MM/DD/YYYY') from dual union all
select 1,     102,     to_date('01/26/2010', 'MM/DD/YYYY'),     to_date('12/31/2900', 'MM/DD/YYYY') from dual union all
select 2,     201,     to_date('03/01/2011', 'MM/DD/YYYY'),     to_date('03/10/2011', 'MM/DD/YYYY') from dual union all
select 2,     202,     to_date('03/11/2011', 'MM/DD/YYYY'),     to_date('12/31/2900', 'MM/DD/YYYY') from dual union all
select 3,     301,     to_date('01/05/2010', 'MM/DD/YYYY'),     to_date('01/09/2010', 'MM/DD/YYYY') from dual union all
select 3,     302,     to_date('01/10/2010', 'MM/DD/YYYY'),     to_date('01/25/2010', 'MM/DD/YYYY') from dual union all
select 3,     303,     to_date('01/26/2010', 'MM/DD/YYYY'),     to_date('01/28/2010', 'MM/DD/YYYY') from dual union all
select 3,     304,     to_date('01/29/2010', 'MM/DD/YYYY'),     to_date('12/31/2900', 'MM/DD/YYYY') from dual
select cola, colb, st_dt, ed_dt
  from (
        select cola, colb, st_dt, ed_dt,
               row_number() over (partition by cola order by st_dt) rn
          from data
       ) a
where a.rn = 1;
COLA COLB ST_DT     ED_DT  
   1  100 05-JAN-10 09-JAN-10
   2  201 01-MAR-11 10-MAR-11
   3  301 05-JAN-10 09-JAN-10

Similar Messages

  • Function used in SQL query not showing the desired results

    I have created a function that gives me the client id but when i am using the function in the query its not giving me any result i.e. 0 rows but if I execute the function sepreatly and put the result of that function in the qurey it is giving me the desired result please have a look on the following and please reply with you expert opinion:
    FUNCTION CODE:
    create or replace function j2
    (usid in varchar2)
    return varchar2
    is
    cidn_in varchar2(4000) := '';
    ls_sep varchar2(1) := ',';
    cursor predicate_cidn
    is
    select
    logical_schema_id
    from
    CLIENT_REGISTRY cr,
    MEMBER_ROLE_CLIENT_ASSIGNMENT mrca,
    MEMBER m
    where
    mrca.base_client_id = cr.base_client_id and
    mrca.member_id = m.member_id and
    cr.schema_in_use_in = '1' and
    m.active_status_id = 'A' and
    upper(mrca.member_id) = upper(usid);
    BEGIN
    for GET_CIDN in predicate_cidn
    loop
    cidn_in := cidn_in || ls_sep || '''' || GET_CIDN.logical_schema_id || '''';
    end loop;
    cidn_in := substr(cidn_in, 2);
    cidn_in := '('||cidn_in||')';
    --dbms_output.put_line(cidn_in);
    return cidn_in;
    END ;
    SQL> select j2('qaa@adp') from dual;
    J2('QAA@ADP')
    ('BASE18','SDK1TEST','SEETHA1CONFIG','BASE09','KAREN2','SIVACONFIG','BASE19','SD
    K1CTEST','VASU1','KAREN5','EVENTS1CTEST','SDK1','ADA1CONFIG','BASE10','VRB1CONFI
    G','CRU2CONFIG','BASE20','SIVATEST','PCOMCONFIG','KP1CONFIG','KAREN4CONFIG','EVE
    NTS1TEST','SUZ3CONFIG','DONG2CONFIG','ED2CONFIG','SIVACTEST','APDCONFIG','EVENTS
    1CONFIG','ESSCONFIG','SIVA','SDK2CONFIG','ED3CONFIG','RAJ4CONFIG','CBRCONFIG','N
    AMRATA2CONFIG','EMIL1','NAMRATA1CONFIG','SDK2CTEST','BVT2CONFIG','MURUGAN1CONFIG
    ','COB1CONFIG','GABY1TEST','CHR1CONFIG','ED4CONFIG','USE1CONFIG','SDK2TEST','DEM
    O1CONFIG','BERNIE1CONFIG','XA1','CAR2TEST','SDK2','ED5CONFIG','PAY1TEST','PAYXCO
    NFIG','KP1TEST','SEAN1CONFIG','CAR2CTEST','VASU1CONFIG','SEAN2CONFIG','KP1CTEST'
    ,'MAU1CONFIG','CONWCONFIG','PAN1CONFIG','MERAJ2','PRA3CONFIG','SEAN5CONFIG','KP1
    ','PRA4CONFIG','CAR2CONFIG','PRA2CONFIG','SEAN6CONFIG','PRA3TEST','RPT','GABY1CT
    EST','SDK3CONFIG','PRA2TEST','SEAN9CONFIG','CAR2','LV1CONFIG','PRA3CTEST','DONG1
    CONFIG','TE1CONFIG','MERAJ2CONFIG','VIV1CONFIG','GABY1','SEAN2','PRA2CTEST','PRA
    3','RPTCONFIG','PRA4CTEST','SEAN3','MITA1CONFIG','PRA2','RPTCTEST','PCOM1CONFIG'
    ,'SS2CONFIG','PAY1CONFIG','SEAN7','ANNCONFIG','BASE11','BASE02','LV2CONFIG','RPT
    TEST','IMPECONFIG','SUR1CONFIG','SREEK2CONFIG','BASE03','SRINU3CONFIG','BDCONFIG
    ','JAY1CONFIG','AMMAN1','PRA1TEST','WPGCONFIG','BASE12','MP5CONFIG','MERAJ1','SR
    INU2CONFIG','XA1CONFIG','RAJ1CONFIG','WPGCTEST','BASE04','CHRIS','RAJSCONFIG','P
    ANKAJ','BASE13','WPGTEST','RAJ3CONFIG','WPG','BASE14','VASU2CONFIG','SRINU1CONFI
    G','BASE05','PRA4TEST','VASU1TEST','PRA5CONFIG','NISH1CONFIG','CHRISCONFIG','SDK
    3TEST','RAJ3TEST','KP2CONFIG','BASE06','DEFPCONFIG','NISH2CONFIG','CHRISCTEST','
    WPSCONFIG','VASU2TEST','BASE15','GABY1CONFIG','PRA5TEST','MITA2CONFIG','BASE07',
    'VASU1CTEST','KP2TEST','VASU2CTEST','LAURA3CONFIG','BASE16','CHRISTEST','WPSTEST
    ','VASU2','KP2CTEST','EVENTS1','BASE17','RAJ2CONFIG','WPSCTEST','BASE08','SREEK1
    CONFIG','ADVE','PRA4','SDK1CONFIG','KP2','KAREN1','CRU1CONFIG','WPS')
    Now if i put the results (cut and paste )in the query it gives me the results
    SQL> select count(*) from baseclient.address_detail where cidn in ('BASE18','SDK1TEST','SEETHA1CONFIG','BASE09','KAREN2','SIVACONFIG','BASE19','SD
    2 K1CTEST','VASU1','KAREN5','EVENTS1CTEST','SDK1','ADA1CONFIG','BASE10','VRB1CONFI
    3 G','CRU2CONFIG','BASE20','SIVATEST','PCOMCONFIG','KP1CONFIG','KAREN4CONFIG','EVE
    4 NTS1TEST','SUZ3CONFIG','DONG2CONFIG','ED2CONFIG','SIVACTEST','APDCONFIG','EVENTS
    5 1CONFIG','ESSCONFIG','SIVA','SDK2CONFIG','ED3CONFIG','RAJ4CONFIG','CBRCONFIG','N
    6 AMRATA2CONFIG','EMIL1','NAMRATA1CONFIG','SDK2CTEST','BVT2CONFIG','MURUGAN1CONFIG
    7 ','COB1CONFIG','GABY1TEST','CHR1CONFIG','ED4CONFIG','USE1CONFIG','SDK2TEST','DEM
    O1CONFIG','BERNIE1CONFIG','XA1','CAR2TEST','SDK2','ED5CONFIG','PAY1TEST','PAYXCO
    8 9 NFIG','KP1TEST','SEAN1CONFIG','CAR2CTEST','VASU1CONFIG','SEAN2CONFIG','KP1CTEST'
    10 ,'MAU1CONFIG','CONWCONFIG','PAN1CONFIG','MERAJ2','PRA3CONFIG','SEAN5CONFIG','KP1
    11 ','PRA4CONFIG','CAR2CONFIG','PRA2CONFIG','SEAN6CONFIG','PRA3TEST','RPT','GABY1CT
    12 EST','SDK3CONFIG','PRA2TEST','SEAN9CONFIG','CAR2','LV1CONFIG','PRA3CTEST','DONG1
    13 CONFIG','TE1CONFIG','MERAJ2CONFIG','VIV1CONFIG','GABY1','SEAN2','PRA2CTEST','PRA
    14 3','RPTCONFIG','PRA4CTEST','SEAN3','MITA1CONFIG','PRA2','RPTCTEST','PCOM1CONFIG'
    15 ,'SS2CONFIG','PAY1CONFIG','SEAN7','ANNCONFIG','BASE11','BASE02','LV2CONFIG','RPT
    16 TEST','IMPECONFIG','SUR1CONFIG','SREEK2CONFIG','BASE03','SRINU3CONFIG','BDCONFIG
    17 ','JAY1CONFIG','AMMAN1','PRA1TEST','WPGCONFIG','BASE12','MP5CONFIG','MERAJ1','SR
    18 INU2CONFIG','XA1CONFIG','RAJ1CONFIG','WPGCTEST','BASE04','CHRIS','RAJSCONFIG','P
    19 ANKAJ','BASE13','WPGTEST','RAJ3CONFIG','WPG','BASE14','VASU2CONFIG','SRINU1CONFI
    20 G','BASE05','PRA4TEST','VASU1TEST','PRA5CONFIG','NISH1CONFIG','CHRISCONFIG','SDK
    21 3TEST','RAJ3TEST','KP2CONFIG','BASE06','DEFPCONFIG','NISH2CONFIG','CHRISCTEST','
    22 WPSCONFIG','VASU2TEST','BASE15','GABY1CONFIG','PRA5TEST','MITA2CONFIG','BASE07',
    23 'VASU1CTEST','KP2TEST','VASU2CTEST','LAURA3CONFIG','BASE16','CHRISTEST','WPSTEST
    24 ','VASU2','KP2CTEST','EVENTS1','BASE17','RAJ2CONFIG','WPSCTEST','BASE08','SREEK1
    25 CONFIG','ADVE','PRA4','SDK1CONFIG','KP2','KAREN1','CRU1CONFIG','WPS');
    COUNT(*)
    228
    BUT if I user the function it gives me no results
    0 rows selected and its taking a loon time to reurn

    This appears to be a duplicate of the question in this thread
    Re: VPD issue Need Assistance ASAP
    where I wrote
    "Your function returns a single string that happens to have a bunch of commas and quotes in it. An IN list generally requires a list of strings, which your function doesn't return.
    You could rewrite the function to be a pipelined table function and then do
    select count(*)
    from baseclient.address_detail
    where cidn in (SELECT cidn
    FROM TABLE(<<your pipelined table function>>))
    However, I would expect it to be easier not to wrap all this into a function and just have your IN clause be the logic in your predicate_cidn cursor.
    Justin
    "

  • Query:  Not getting the desired result. Please help

    QL> select * from ecev;
    entity_Tag
    7
    8
    9
    10
    1
    2
    3
    4
    5
    6
    SQL> select * from dg;
    DIGP_TAG CEPT_TAG
    600 1
    700 1
    800 1
    900 1
    100 1
    200 1
    500 1
    75 2
    SQL> select * from enow;
    ENTITY_CODE ENTITY_TAG DIGP_TAG TARGET_DA CEPT_TAG
    EXT 7           600      26-MAY-07 1
    EXT 8           700      26-MAY-07 1
    EXT 9           800      26-MAY-07 1
    EXT 10           800      22-APR-76 1
    EXT 1           100      20-OCT-06 1
    EXT 2           200      20-OCT-06 1
    EXT 3           500      20-OCT-06 1
    EXT 4           100      20-OCT-06 1
    EXT 5           100      20-OCT-06 1
    EXT 6           80      20-OCT-06 1
    EXT 1           75           2
    SQL> select * from tk;
    TK_TAG DIGP_TAG NARRATIVE DUE_DATE CEPT_TAG
    35 90 raj 27-MAY-07               1
    36 900 kkd 27-MAY-07               1
    37 100 kim 28-MAY-07               1
    30 100 ram 23-MAY-07               1
    31 100 kish 23-MAY-07               1
    32 200 mar 23-MAY-07               1
    33 100 gy 23-MAY-07               1
    34 100 mm 27-MAY-07               1
    8 rows selected.
    For the following query
    1 select
    2 d.ecev_tag ecev_tag,
    3 a.digp_tag entity_owner ,
    4 c.digp_tag task_owner,
    5 c.tk_tag task_tag,
    6 c.narrative
    7 from enow a,
    8 entl b,
    9 tk c,
    10 ecev d
    11 where ( a.DIGP_TAG=100 or c.digp_tag=100)
    12 and a.entity_tag=b.entity_tag(+)
    13 and b.tk_tag=c.tk_tag(+)
    14* and a.entity_tag=d.entity_tag
    SQL> select * from entl;
    TK_TAG ENTITY_TAG
    35 5
    36 10
    30 1
    31 1
    32 2
    33 3
    34 3
    Result:
    I get
    entity_tag ENTITY_OWNER TASK_OWNER TASK_TAG NARRATIVE
    5 100 90 35 raj          row1
    1 100 100 30 ram          row2
    1 75 100 30 ram          row3 1 100 100 31 kish          row4
    1 75 100 31 kish          row5 3 500 100 33 gy          row6
    3 500 100 34 mm          row7
    4 100                              row8
    Row1: yes, since entity_tag 5 is owned by digp_tag 100 (enow)
    Row2: yes, since entity_tag 1 is owned by digp_tag 100 (enow)
    Row3: NO, since entity_tag 1 is owned by digp_tag 75, which in turn is in cept_tag 2, since the passed digp_tag is 100 and it just belongs to cept_tag 1 we should not be getting this row.
    Row4: Yes, since tk_tag 31 is owned by digp_tag 100 (tk)
    Row5 NO, since entity_tag 1 is owned by digp_tag 75, which in turn is in cept_tag 2 since the passed digp_tag is 100 and it just belongs to cept_tag 1 we should not be getting this row.
    Row6: Yes, since tk_tag 33 is owned by digp_tag 100 (enow)
    Row7: Yes, since tk_tag 34 is owned by digp_tag 100(enow)
    Row8: Yes, since entity_tag 4 is owned by 100(enow
    I guess i have to join dg.cept_tag and a.cept_tag, but it is not working.....
    Can somebody understand this and help...
    Thanks
    Ram

    QL> select * from ecev;
    entity_Tag
    7
    8
    9
    0
    1
    2
    3
    4
    5
    6
    SQL> select * from dg;
    DIGP_TAG CEPT_TAG
    600 1
    700 1
    800 1
    900 1
    100 1
    200 1
    500 1
    75 2
    SQL> select * from enow;
    ENTITY_CODE ENTITY_TAG DIGP_TAG
    TARGET_DA CEPT_TAG
    EXT 7
              600      26-MAY-07 1
    8           700
         26-MAY-07 1
    EXT 9
              800      26-MAY-07 1
    10           800
         22-APR-76 1
    EXT 1
              100      20-OCT-06 1
    2           200
         20-OCT-06 1
    EXT 3
              500      20-OCT-06 1
    4           100
         20-OCT-06 1
    EXT 5
              100      20-OCT-06 1
    6           80
         20-OCT-06 1
    EXT 1
              75           2
    L> select * from tk;
    TK_TAG DIGP_TAG NARRATIVE DUE_DATE
    CEPT_TAG
    35 90 raj 27-MAY-07               1
    36 900 kkd 27-MAY-07               1
    37 100 kim 28-MAY-07               1
    30 100 ram 23-MAY-07               1
    31 100 kish 23-MAY-07               1
    32 200 mar 23-MAY-07               1
    33 100 gy 23-MAY-07               1
    34 100 mm 27-MAY-07               1
    8 rows selected.
    For the following query
    1 select
    2 d.ecev_tag ecev_tag,
    3 a.digp_tag entity_owner ,
    4 c.digp_tag task_owner,
    5 c.tk_tag task_tag,
    6 c.narrative
    7 from enow a,
    8 entl b,
    9 tk c,
    10 ecev d
    11 where ( a.DIGP_TAG=100 or c.digp_tag=100)
    12 and a.entity_tag=b.entity_tag(+)
    13 and b.tk_tag=c.tk_tag(+)
    14* and a.entity_tag=d.entity_tag
    SQL> select * from entl;
    TK_TAG ENTITY_TAG
    35 5
    36 10
    30 1
    31 1
    32 2
    33 3
    34 3
    sult:
    I get
    entity_tag ENTITY_OWNER TASK_OWNER TASK_TAG
    NARRATIVE
    5 100 90
    35 raj          row1
    100 100 30
    ram          row2
    75 100
    30 ram          row31 100 100
    31 kish          row4
    75 100
    31 kish          row5
    3 500 100
    33 gy          row6
    500 100 34
    mm          row7
    100                              row8
    1: yes, since entity_tag 5 is owned by digp_tag 100
    (enow)
    Row2: yes, since entity_tag 1 is owned by digp_tag
    100 (enow)
    Row3: NO, since entity_tag 1 is owned by digp_tag 75,
    which in turn is in cept_tag 2, since the passed
    digp_tag is 100 and it just belongs to cept_tag 1 we
    should not be getting this row.
    Row4: Yes, since tk_tag 31 is owned by digp_tag 100
    (tk)
    Row5 NO, since entity_tag 1 is owned by digp_tag 75,
    which in turn is in cept_tag 2 since the passed
    digp_tag is 100 and it just belongs to cept_tag 1 we
    should not be getting this row.
    Row6: Yes, since tk_tag 33 is owned by digp_tag 100
    (enow)
    Row7: Yes, since tk_tag 34 is owned by digp_tag
    100(enow)
    Row8: Yes, since entity_tag 4 is owned by 100(enow
    I guess i have to join dg.cept_tag and a.cept_tag,
    but it is not working.....
    Can somebody understand this and help...
    Thanks
    Ram
    Result:
    I get
    entity_tag ENTITY_OWNER TASK_OWNER TASK_TAG NARRATIVE
    5 100 90 35 raj     row1
    1 100 100 30 ram     row2
    1 75 100 30 ram     row3
    1 100 100 31 kish     row4
    1 75 100 31 kish     row5
    3 500 100 33 gy     row6
    3 500 100 34 mm     row7
    4 100                    row8

  • Query to get the hierarchical results

    Hi,
    Please help me in writing a Query to get the hierarchical results. I want a result like follows...
    course-----groupname---TotalMembers---NotStarted---INProgress---Completed
    Course1---country1--------12---------------6----------3-------------3
    Course1-----state11-------12---------------6----------3-------------3
    Course1------District111--10---------------5----------0-------------0
    Course1--------City1111----0---------------0----------0-------------0
    Course1--------City1112----1---------------0----------0-------------1
    Course1--------City1113----6---------------3----------2-------------1
    Course1---country2--------12---------------6----------3-------------3
    Course1----state21--------12---------------6----------3-------------3
    Course1------District211--10---------------5----------0-------------0
    Course1--------City2111----0---------------0----------0-------------0
    Course1--------City2112----1---------------0----------0-------------1
    Course1--------City2113----6---------------3----------2-------------1
    Course2---country1--------12---------------6----------2-------------3
    Course2----state11--------12---------------6----------2-------------3
    Course2------District111--10---------------5----------0-------------0
    Course2--------City1111----0---------------0----------0-------------0
    Course2--------City1112----1---------------0----------0-------------1
    Course2--------City1113----6---------------3----------1-------------2
    Course2---country2--------12---------------6----------3-------------3
    Course2-----state21-------12---------------6----------3-------------3
    Course2------District211--10---------------5----------0-------------0
    Course2--------City2111----0---------------0----------0-------------0
    Course2--------City2112----1---------------0----------0-------------1
    Course2--------City2113----6---------------3----------2-------------1
    These are the Tables available to me.
    (I have just given some examle data in tables, to get the idea)
    "Groups" Table (This table gives the information of the group)
    GROUPID-----NAME-------PARENTID
    1---------Universe--------1
    2---------country1--------1
    3---------state11---------2
    4---------District111-----3
    5---------City1111--------4
    6---------City1112--------4
    7---------City1113--------4
    8---------country2--------1
    9---------state21---------8
    10--------District211-----9
    11--------City2111--------10
    12--------City2112--------10
    13--------City2113--------10
    "Users" Table (This table provides the user information)
    userID----FIRSTNAME---LASTNAME
    user1-----------Jim-------Carry
    user2-----------Tom-------lee
    user3-----------sunny-----boo
    user4-----------mary------mall
    "User-Group" Tables (This table provides the relation between the groups
    and the members)
    GROUPID---userID
    3-------------user1
    3-------------user2
    3-------------user4
    4-------------user5
    5-------------user6
    5-------------user7
    user_score (This table provides the user scores of different courses)
    USERID----course-----STATUS
    user1------course1-----complete
    user1------course2-----NotStarted
    user2------course1-----NotStarted
    user2------course2-----complete
    user3------course1-----complete
    user3------course2-----InProgress
    user4------course2-----complete
    user4------course1-----NotStarted
    I will explain the first four lines of the above result.
    Course1---country1--------12---------------6----------4-------------2
    Course1-----state11-------12---------------6----------4-------------2
    Course1------District111--10---------------5----------3-------------2
    Course1--------City1111----0---------------0----------0-------------0
    Course1--------City1112----1---------------0----------0-------------1
    Course1--------City1113----6---------------3----------2-------------1
    # "city1111" group has 0 members
    # "city1112" group has 1 member (1 member completed the course1)
    # "city1113" group has 6 members(3 members notStarted,2 members
    InProgress,1 member completed the course1)
    # "District111" is the parent group of above three groups, and has 3
    members.(2 members NotStarted,1 member InProgress the course1). But this
    group has child groups, so the scores of this group has to rollup the
    child groups scores also. Thats why it has 2+3+0+0=6 members Not
    Started,1+2+0+0=3 members InProgress,0+0+1+1=2 members completed.
    # "state11" group also same as the above group.
    I am able to get the group hierarchy by using "Connect By" like follows
    "select name,groupid,parentid from groups_info start with groupid=1 connect by parentid = prior groupid;"
    But i want to get the result as i have mentioned in the begining of this discussion.
    I am using oracle 8i (oracle8.1.7).
    Thank you for any help
    Srinivas M

    This may not be exactly what you want,
    but it should be fairly close:
    SET      LINESIZE 100
    SET      PAGESIZE 24
    COLUMN   groupname FORMAT A20
    SELECT   INITCAP (user_score.course) "course",
             groupnames.name "groupname",
             COUNT (*) "TotalMembers",
             SUM (NVL (DECODE (UPPER (user_score.status), 'NOTSTARTED', 1), 0)) "NotStarted",
             SUM (NVL (DECODE (UPPER (user_score.status), 'INPROGRESS', 1), 0)) "InProgress",
             SUM (NVL (DECODE (UPPER (user_score.status), 'COMPLETE', 1), 0)) "Completed"
    FROM     user_score,
             user_group,
             (SELECT ROWNUM rn,
                     name,
                     groupid
              FROM   (SELECT     LPAD (' ', 2 * LEVEL - 2) || name AS name,
                                 groupid
                      FROM       groups
                      START WITH groupid = 1
                      CONNECT BY PRIOR groupid = parentid)) groupnames
    WHERE    user_score.userid = user_group.userid
    AND      user_group.groupid IN
             (SELECT     groupid
              FROM       groups
              START WITH groupid = groupnames.groupid
              CONNECT BY PRIOR groupid = parentid)
    GROUP BY user_score.course, groupnames.name, groupnames.rn
    ORDER BY user_score.course, groupnames.rn
    I entered the minimal test data that you
    provided and a bit more and got this result
    (It was formatted as you requested,
    but I don't know if it will display properly
    on this post, or wrap around):
    course  groupname            TotalMembers NotStarted InProgress  Completed
    Course1 Universe                        6          2          0          4
    Course1   country1                      5          2          0          3
    Course1     state11                     5          2          0          3
    Course1       District111               2          0          0          2
    Course1         City1112                1          0          0          1
    Course1         City1113                1          0          0          1
    Course1   country2                      1          0          0          1
    Course1     state21                     1          0          0          1
    Course1       District211               1          0          0          1
    Course1         City2113                1          0          0          1
    Course2 Universe                        5          1          1          3
    Course2   country1                      4          1          1          2
    Course2     state11                     4          1          1          2
    Course2       District111               1          0          1          0
    Course2         City1113                1          0          1          0
    Course2   country2                      1          0          0          1
    Course2     state21                     1          0          0          1
    Course2       District211               1          0          0          1
    Course2         City2113                1          0          0          1
    Here is the test data that I used, in case
    anyone else wants to play with it:
    create table groups
      (groupid  number,
       name     varchar2(15),
       parentid number)
    insert into groups
    values (1,'Universe',null)
    insert into groups
    values (2,'country1',1)
    insert into groups
    values (3,'state11',2)
    insert into groups
    values (4,'District111',3)
    insert into groups
    values (5,'City1111',4)
    insert into groups
    values (6,'City1112',4)
    insert into groups
    values (7,'City1113',4)
    insert into groups
    values (8,'country2',1)
    insert into groups
    values (9,'state21',8)
    insert into groups
    values (10,'District211',9)
    insert into groups
    values (11,'City2111',10)
    insert into groups
    values (12,'City2112',10)
    insert into groups
    values (13,'City2113',10)
    create table user_group
      (groupid number,
       userid  varchar2(5))
    insert into user_group
    values (3,'user1')
    insert into user_group
    values (3,'user2')
    insert into user_group
    values (3,'user4')
    insert into user_group
    values (4,'user5')
    insert into user_group
    values (5,'user6')
    insert into user_group
    values (5,'user7')
    insert into user_group
    values (7,'user8')
    insert into user_group
    values (13,'user9')
    insert into user_group
    values (11,'use11')
    insert into user_group
    values (6,'use6')
    create table user_score
      (userid varchar2(5),
       course varchar2(7),
       status varchar2(10))
    insert into user_score
    values ('use6','course1','complete')
    insert into user_score
    values ('user9','course1','complete')
    insert into user_score
    values ('user9','course2','complete')
    insert into user_score
    values ('user8','course1','complete')
    insert into user_score
    values ('user8','course2','InProgress')
    insert into user_score
    values ('user1','course1','complete')
    insert into user_score
    values ('user1','course2','NotStarted')
    insert into user_score
    values ('user2','course1','NotStarted')
    insert into user_score
    values ('user2','course2','complete')
    insert into user_score
    values ('user3','course1','complete')
    insert into user_score
    values ('user3','course2','InProgress')
    insert into user_score
    values ('user4','course2','complete')
    insert into user_score
    values ('user4','course1','NotStarted')

  • SQL query to get the Datetime 06 hours prior to the table Datetime value

    Hi Experts,
                    I'm just trying to create a SQL query to get the Datetime which should be 06 hours prior to my Table column value(Executiontime),
    Eg: my Executiontime(column) value is 07:00AM means, this query should fetch the detail of first VMName from table at 01:00AM, 
    SQL Table Name: TestTable
    Columns: VMName(varchar),status(varchar) Executiontime(Datetime)
    SQL Query : Select Top 1 VMName from
    TestTable where convert(date,Exeutiontime)=convert(date,getdate()) and
    status='0' and ExecutionTime > dateadd(hour,6,getdate())
    Request someone to alter this Query to my requirement or give me the new one.
    Regards,
    Sundar
    Sundar

    Hi All,
            Thanks for your Prompt response. I tried the below queries, but still I don't have any luck. Actually the queries are returning the value before the condition met (say when the time difference is more than 06 hours). I want the
    query to return exactly @ 06 hour difference or less than 06 hours,
    Query 01: Select Top 1 VMName from TestTable where
    convert(date,Exeutiontime)=convert(date,getdate())
    and status='0'
    and ExecutionTime >
    dateadd(hour,-6,getdate())
    Query 02: Select
    Top 1 VMName from TestTable where
    status='0'
    and ExecutionTime >
    dateadd(hour,-6,getdate())
    Query 03: Select
    Top 1 VMName from TestTable where status='0'
    and ExecutionTime >
    dateadd(hour,-6,ExecutionTime)
              Can someone point out the mistake please.
    Regards,
    Sundar
    Sundar

  • SQL query to get the list of approvals

    Hi,
    Could someone let me know the SQL query to get the list of all the pending approvals for a user in OIM 11g R2.
    Thanks

    There are a few ways to do this:
    -  The easiest would be to use a Relationship Query from the CMC. To do this, go to the Universes section on the CMC, right click on the relevant universe, select tools >> Check Relationships.
    - Use Query Builder. You will need more than one query to pull the information you need. You could try something like the below (for Webi)
    SELECT SI_NAME, SI_WEBI, SI_DATACONNECTION FROM CI_APPOBJECTS
    WHERE SI_KIND = 'universe' and SI_NAME = 'Universe Name'
    This will give you a list of Webi Reports by SI_ID.
    You'll need another query to list Webi report names:
    SELECT SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID IN (SI_ID from query above)
    - This is trivial via Auditing / the Activity universe. This of course will only return reports that have already run.
    Best.
    Srinivas

  • SQL Query to get the # of files in folders in a library

    Anyone has the SQL query to list the number of files in each folders in a SharePoint library?

    Technically it's a grey area of support as MS don't mind you doing it but won't help you if you encounter problems, the script is much better though.
    Scratch that, the script isn't that good. It's using .items which won't work on large lists and is slow. The version below is untested but should be significantly faster and work on large lists.
    $starttime = Get-Date
    #Creating new site object
    $siteurl = Read-Host "Enter the name of your site and press enter"
    $site = New-Object Microsoft.SharePoint.SPSite($siteurl)
    #Assigning all webs (sites) to $webs
    $webs = $site.Allwebs
    #System Libraries defined so they won't be touched##
    $systemlibs =@("Converted Forms", "Customized Reports", "Documents", "Form Templates",
    "Images", "List Template Gallery", "Master Page Gallery", "Pages",
    "Reporting Templates", "Site Assets", "Site Collection Documents",
    "Site Collection Images", "Site Pages", "Solution Gallery",
    "Style Library", "Theme Gallery", "Web Part Gallery", "wfpub")
    Write-Host "Total number of webs that will be traversed: " $webs.count
    $DocLibsCount = 0
    $DocLibwItems = 0
    $totalitems = 0
    $subfolderitems = 0
    foreach($web in $webs)
    $listcoll = $web.lists
    foreach($list in $listcoll)
    if($list -eq $null)
    Write-Host
    else
    $base = $list.GetType()
    if($base.name -eq "SPDocumentLibrary")
    if ($systemlibs -contains $list)
    { continue}
    else
    $DocLibsCount += 1
    $totalitems += $List.itemcount
    $name = $list.Title
    $folders = $web.GetFolder($name).SubFolders
    for($etr = 0;$etr -lt $folders.count; $etr++)
    if($folders[$etr].Name -ne "Forms")
    Write-Host "Processing SubFolder ItemCount" -ForegroundColor Red
    $tempcount = $folders[$etr].ItemCount
    $subfolderitems += $tempcount
    Write-Host
    Write-Host
    Write-Host "Total # of Document Libraries: " $DocLibsCount -ForegroundColor Green
    Write-Host "Total # of Document Libraries that contain items: " $DocLibwItems -ForegroundColor Green
    Write-Host "Total # of items: " $totalitems -ForegroundColor Green
    Write-Host "Total # of items in DocLib\Subfolders: " $subfolderitems -ForegroundColor Green
    $finishtime = Get-Date
    Write-Host
    Write-Host “Script Duration” –ForegroundColor Yellow
    Write-Host “Started: “ $starttime –ForegroundColor Yellow
    Write-Host “Finished: “ $finishtime –ForegroundColor Yellow
    Stop-SPAssignment -Global

  • OIM sql Query for getting the status of the task which got failed

    Hi Everyone,
    We have a requirement like we need to get the status of a particular task(say Create User in OID resource - Completed\Rejected status) for the particular user.We are able to get the status of the resource provisioed to the user but not the status of the particular task getting trigerred for the user.can someone put some light on this.We need to get the SQL query for this.
    Thanks in Advance.
    Regards,
    MKN

    Hi
    Use this sample query to get the task status, also check the cooments
    SELECT USR.USR_LOGIN, OSI.SCH_KEY,SCH.SCH_STATUS,STA.STA_BUCKET FROM
    OSI,SCH,STA,MIL,TOS,PKG,OIU,USR,OBJ,OST
    WHERE OSI.MIL_KEY=MIL.MIL_KEY
    AND SCH.SCH_KEY=OSI.SCH_KEY
    AND STA.STA_STATUS=SCH.SCH_STATUS
    AND TOS.PKG_KEY=PKG.PKG_KEY
    AND MIL.TOS_KEY=TOS.TOS_KEY
    AND OIU.USR_KEY=USR.USR_KEY
    AND OIU.OST_KEY=OST.OST_KEY
    AND OST.OBJ_KEY=OBJ.OBJ_KEY
    AND OSI.ORC_KEY=OIU.ORC_KEY
    AND OBJ.OBJ_NAME='AD User'
    AND OST.OST_STATUS = 'Provisioning' -- filter accordinglly
    AND STA.STA_BUCKET = 'Pending' -- filter accordinglly
    AND PKG.PKG_NAME='AD User' -- filter accordinglly
    AND MIL.MIL_NAME='System Validation' ---- filter accordinglly
    Thanks,
    Kuldeep

  • Need SQL query to get the result.

    Region
    Month
    Trx Type
    Resolution Summary
    AMERICAS
    May-13
    Adjustments
    Correct
    EMEA
    May-13
    Adjustments
    Incorrect
    AMERICAS
    May-13
    Credit Memo
    Incorrect
    EMEA
    May-13
    Invoice
    Correct
    AMERICAS
    May-13
    Credit Memo
    Correct
    OFD
    May-13
    Adjustments
    Correct
    AMERICAS
    May-13
    Invoice
    Incorrect
    LAD
    May-13
    Adjustments
    Correct
    LAD
    May-13
    Adjustments
    Correct
    OFD
    May-13
    Adjustments
    Correct
    Above is my Table and find below the required result.Similarly for other regions as well. Can anyone help me with the SQL Query?
    Region
    Resolution Summary
    Adjustment
    Credit Memo
    Invoice
    Grand Total
    AMERICAS
    Correct
    1
    1
    2
    Incorrect
    0
    1
    1
    2

    Like this?
    SQL> select * from transaction_audit;
    REGION   MTH    TRX_TYPE    RESOLUTIO
    AMERICAS may-13 ADJUSTMENTS CORRECT
    EMEA     may-13 ADJUSTMENTS INCORRECT
    AMERICAS may-13 CREDIT MEMO INCORRECT
    EMEA     may-13 INVOICE     CORRECT
    AMERICAS may-13 CREDIT MEMO CORRECT
    OFD      may-13 ADJUSTMENTS CORRECT
    AMERICAS may-13 INVOICE     INCORRECT
    LAD      may-13 ADJUSTMENTS CORRECT
    LAD      may-13 ADJUSTMENTS CORRECT
    OFD      may-13 ADJUSTMENTS CORRECT
    10 rows selected.
    SQL> select region
      2       , resolution_summary
      3       , count(decode(trx_type, 'ADJUSTMENTS', trx_type)) adjustments
      4       , count(decode(trx_type, 'CREDIT MEMO', trx_type)) credit_memo
      5       , count(decode(trx_type, 'INVOICE'    , trx_type)) invoice
      6    from transaction_audit
      7   group
      8      by region
      9       , resolution_summary
    10   order
    11      by region
    12       , resolution_summary
    13  /
    REGION   RESOLUTIO ADJUSTMENTS CREDIT_MEMO    INVOICE
    AMERICAS CORRECT             1           1          0
    AMERICAS INCORRECT           0           1          1
    EMEA     CORRECT             0           0          1
    EMEA     INCORRECT           1           0          0
    LAD      CORRECT             2           0          0
    OFD      CORRECT             2           0          0
    6 rows selected.
    SQL>

  • SQL query to get the without SCCM agent for a Server

    Hello every one,
    Can I get the SQL query for a server without a SCCM agent . 

    Here you go!!
    Add the version for windows 2012 server if you have them as well in your environment
       v_R_System.Netbios_Name0
      ,v_R_System.Full_Domain_Name0
      ,v_R_System.User_Name0
      ,case
    When v_R_System.Operating_System_Name_and0 LIKE N'%Server 6.1'THEN 'Windows Server 2008 R2'
    When v_R_System.Operating_System_Name_and0 LIKE N'%Server 6.0'THEN 'Windows Server 2008'
    When v_R_System.Operating_System_Name_and0 LIKE N'%Server 5.2'THEN 'Windows Server 2003 R2'
     ELSE 'Unknown Version' END AS 'OS version'
    FROM
      v_R_System
    WHERE
      v_R_System.Operating_System_Name_and0 LIKE N'%server%' and v_R_System.Client0 is null
    Kindly mark as answer/Vote as helpful if a reply from anybody helped you in this forum. Delphin

  • SQL query to get the monitor target on a monitor

    Hi!
    I have a list of some custom created Monitors. I need a list of which computers that are using the monitors, the "Monitor target". Please help me with this. It need to be a SQL Query because my powershell have stopped working.

    Yes that is what i have explained you with the screenshot right it is the one in your screen shot also which is mentioned as (This). If this is a default group then you will not get agents for that refer the below link on how to pull agent list of the Target
    group
    http://msdn.microsoft.com/en-us/library/bb960484.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
    Or look at this. You can see what groups the agents are associated manually one by one by using the default SCOM Task.
    Go to Administration==> Agent managed==> Select the agent ==> Right click it and click View ==> Select state view.
    Once you select this you will have another window opened for that particular agent.
    Then click on the name of the agent and on the right hand side bottom you will have a default made task to check to what group's or Targets this agent is associated to. Run that task and you will get the output.
    Look at the ones highlighted in RED
    Below is the screenshot for your reference. Hope this helps
    Gautam.75801

  • To write a single query to get the desired output.

    Hi,
    I have table by name "employees" it contains 20 records meaning 20 employee details.
    some of the column it contains are employee_id,Hiredate as below.
    EMPLOYEE_ID|HIRE_DATE
    100|6/17/1987
    101|9/21/1989
    102|1/13/1993
    103|1/3/1993
    104|5/21/1991
    107|2/7/1999
    124|11/16/1999
    141|10/17/1995
    142|1/29/1997
    143|3/15/1998
    144|7/9/1998
    149|1/29/2000
    174|5/11/1996
    176|3/24/1998
    178|5/24/1999
    200|9/17/1987
    201|2/17/1996
    202|8/17/1997
    205|6/7/1994
    206|6/7/1994
    The query should display the total number of employees, employees hired in 1995,1996,1997 and 1998 some thing like below.
    output
    Total     1995     1996     1997     1998
    20     1     2     2     3
    please let me know the query.
    Thanks
    Dinesh

    SQL> select * from employees;
             EMPLOYEE_ID HIRE_DATE
                     100 17-JUN-1987 00:00:00
                     101 21-SEP-1989 00:00:00
                     102 13-JAN-1993 00:00:00
                     103 03-JAN-1993 00:00:00
                     104 21-MAY-1991 00:00:00
                     107 07-FEB-1999 00:00:00
                     124 16-NOV-1999 00:00:00
                     141 17-OCT-1995 00:00:00
                     142 29-JAN-1997 00:00:00
                     143 15-MAR-1998 00:00:00
                     144 09-JUL-1998 00:00:00
                     149 29-JAN-2000 00:00:00
                     174 11-MAY-1996 00:00:00
                     176 24-MAR-1998 00:00:00
                     178 24-MAY-1999 00:00:00
                     200 17-SEP-1987 00:00:00
                     201 17-FEB-1996 00:00:00
                     202 17-AUG-1997 00:00:00
                     205 07-JUN-1994 00:00:00
                     206 07-JUN-1994 00:00:00
    20 rows selected.
    SQL> select count(*) total_employees
      2        ,sum(case when to_char(hire_date,'YYYY') = '1995' then 1 else 0 end) hired_1995
      3        ,sum(case when to_char(hire_date,'YYYY') = '1996' then 1 else 0 end) hired_1996
      4        ,sum(case when to_char(hire_date,'YYYY') = '1997' then 1 else 0 end) hired_1997
      5        ,sum(case when to_char(hire_date,'YYYY') = '1998' then 1 else 0 end) hired_1998
      6  from   employees;
         TOTAL_EMPLOYEES           HIRED_1995           HIRED_1996           HIRED_1997           HIRED_1998
                      20                    1                    2                    2                    3Edited by: SomeoneElse on Jan 6, 2009 8:09 AM

  • How to modify this query to get the desired output format

    I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
    SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
    FROM ALL_CONS_COLUMNS
    WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
    FROM ALL_CONSTRAINTS AC
    WHERE AC.TABLE_NAME=TABLE_NAME
    AND AC.TABLE_NAME='&TABLE'
    AND AC.R_CONSTRAINT_NAME IS NOT NULL);
    This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
    I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
    For Example I want the output as follows...
    TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
    CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
    EMP DEPTNO DEPT DEPTNO
    In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
    any help on how to tackle would be appreciated.

    Try this query
    SELECT c.table_name child_table,
         c.column_name child_column,
         p.table_name parent_table,
         p.column_name parent_column
    FROM user_constraints a,user_constraints b,user_cons_columns c,
         user_cons_columns p
    WHERE a.r_constraint_name=b.constraint_name and
          a.constraint_name=c.constraint_name and
          b.constraint_name=p.constraint_name and
          c.position=p.position
    ORDER BY c.constraint_name,c.position
    Anwar

  • SQL query to get the responsibility name

    Hi,
    I require an SQL query which would give the responsibilty name to which the concurrent programs are assigned.
    Thanks& Regards,

    SELECT          fcpv.user_concurrent_program_name
    FROM            fnd_request_groups frg,
                    fnd_request_group_units frgu,
                    fnd_concurrent_programs_vl fcpv,
                    fnd_responsibility_vl frv
    WHERE           frgu.request_group_id = frg.request_group_id
    AND             frgu.request_unit_id = fcpv.concurrent_program_id
    AND             frv.request_group_id = frg.request_group_id
    AND           frgu.request_unit_type = 'P'
    AND             frv.responsibility_name =<Responsibility Name>Regards
    Prashant Pathak

  • SQL query to get the current session info

    I've a query in my application to view the all the sessions within database
    select
    substr(a.spid,1,9) pid,
    substr(b.sid,1,5) sid,
    substr(b.serial#,1,5) ser#,
    substr(b.machine,1,6) box,
    substr(b.username,1,10) username,
    -- b.server,
    substr(b.osuser,1,8) os_user,
    substr(b.program,1,30) program
    from
    v$session b,
    v$process a
    where
    b.paddr = a.addr
    and type='USER'
    order by spid;
    Can someone help me with a query to view the info of the session where I'm in currently?
    Thanks,
    Gabriel Stephen.

    here's one way to do it.
    select
       substr(a.spid,1,9) pid,
       substr(b.sid,1,5) sid,
       substr(b.serial#,1,5) ser#,
       substr(b.machine,1,6) box,
       substr(b.username,1,10) username,
       -- b.server,
       substr(b.osuser,1,8) os_user,
       substr(b.program,1,30) program
    from
       v$session b,
       v$process a
    where
       b.paddr = a.addr
       and type='USER'
       and b.sid=(select sid from v$mystat where rownum=1)
    order by spid-------------
    Anwar

Maybe you are looking for

  • How do I use my second monitor when first monitor in full screen??

    HI.  I just added a second monitor to my mac mini lion setup and when I go full screen with an app I can't use the other monitor.  How do I fix this?  Thanks.

  • Wifi BB curve 8520 :(

    Hi everyone .. well, I have seen all the posts here but, i didn't found an answer for my problem simply said, I turn the wifi on, and when I start scaning he just cant' detect any wifi network .. knowing that there is a wifi network at home from my l

  • No Backend Document created

    we have setup extended classic scenario in SRM 7. The Shopping Cart creates a local PO but there is no backend PO created. We do not see any errors in RZ20 or ST22. Are we missing any config? Appreciate any inputs. Thanks, AB

  • Automatic Download of RSS Feed Content

    Hi, I have read a number of posts on rss feeds, saying that it wasnt possible to see the entire article in the mail application without clicking on "read more". What I want to know is if there is any way to automatically download all content, so that

  • Integrating with Siebel

    Hi, I would like to know how BPEL can be integrated with Siebel. I Read how it could be done in Peoplesoft but can anyone provide any inputs on how it could be done in Siebel. Any kind of documentation in this would be highly appreciated. Thanks in a