HELP NEEDED IN FORMING A QUERY...URGENT.....

Hi,
I have a table where in that an employee has multiple rows,
in that i need to query a particular column values, and need to display
in one column separated any special charactar like ":". I need this query.
ex:
EmpID in_time
1900 9:00:00
1900 9:45:00
1900 10:50:00
Here i want to display this as
EmpID time
1900 9:00;9:45;10:50;
Please give me your valuable contributions...

create table user644354(empid number(4),in_time varchar2(8));
insert into user644354 values(1900,'9:00:00');
insert into user644354 values(1900,'9:45:00');
insert into user644354 values(1900,'10:50:00');
commit;
select substr(max(SYS_CONNECT_BY_PATH(In_Time, ', ')),2) In_Time FROM
(SELECT in_time,ROWNUM NBR FROM (SELECT In_time FROM user644354 e where empid=1900))
CONNECT BY PRIOR NBR = NBR - 1 START WITH NBR = 1
Regards
Girish Sharma

Similar Messages

  • Help needed to optimize the query

    Help needed to optimize the query:
    The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
    This is having high cost and taking around 15mins to execute.
    Can anyone help to fine-tune this??
       SELECT c.H_SEC,
                    c.S_PAID,
                    c.H_PAID,
                    table_c.EFF_DATE
       FROM    MTCH_TBL c
                    LEFT OUTER JOIN
                       (SELECT b.SEC_ALIAS,
                               b.EFF_DATE,
                               b.INSTANCE
                          FROM HIST_TBL b
                         WHERE b.EFF_DATE =
                                  (SELECT MAX (b2.EFF_DATE)
                                     FROM HIST_TBL b2
                                    WHERE b.SEC_ALIAS = b2.SEC_ALIAS
                                          AND b.INSTANCE =
                                                 b2.INSTANCE
                                          AND b2.EFF_DATE >= '01-Jan-2007')
                               OR b.EFF_DATE IS NULL) table_c
                    ON  table_c.SEC_ALIAS=c.H_SEC
                       AND table_c.INSTANCE = 100;

    To start with, I would avoid scanning HIST_TBL twice.
    Try this
    select c.h_sec
         , c.s_paid
         , c.h_paid
         , table_c.eff_date
      from mtch_tbl c
      left
      join (
              select sec_alias
                   , eff_date
                   , instance
                from (
                        select sec_alias
                             , eff_date
                             , instance
                             , max(eff_date) over(partition by sec_alias, instance) max_eff_date
                          from hist_tbl b
                         where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
                            or eff_date is null
               where eff_date = max_eff_date
                  or eff_date is null
           ) table_c
        on table_c.sec_alias = c.h_sec
       and table_c.instance  = 100;

  • Urgent help needed....Query..

    Hello Experts
    Can someone help with writing a particular query. This is the test scenario
    CREATE TABLE TEST (MONTH DATE,
    AMOUNT NUMBER(17));
    INSERT INTO TEST VALUES('01-FEB-06',100);
    INSERT INTO TEST VALUES('01-MAR-06',100);
    INSERT INTO TEST VALUES('01-APR-06',100);
    INSERT INTO TEST VALUES('01-JUN-06',100);
    INSERT INTO TEST VALUES('01-JUL-06',100);
    INSERT INTO TEST VALUES('01-AUG-06',100);
    INSERT INTO TEST VALUES('01-SEP-06',100);
    INSERT INTO TEST VALUES('01-OCT-06',100);
    INSERT INTO TEST VALUES('01-NOV-06',100);
    INSERT INTO TEST VALUES('01-DEC-06',100);
    INSERT INTO TEST VALUES('01-JAN-07',100);
    INSERT INTO TEST VALUES('01-FEB-07',100);
    INSERT INTO TEST VALUES('01-MAR-07',100);
    INSERT INTO TEST VALUES('01-APR-07',100);
    INSERT INTO TEST VALUES('01-MAY-07',100);
    INSERT INTO TEST VALUES('01-JUN-07',100);
    INSERT INTO TEST VALUES('01-JUL-07',100);
    INSERT INTO TEST VALUES('01-AUG-07',100);
    INSERT INTO TEST VALUES('01-SEP-07',100);
    INSERT INTO TEST VALUES('01-OCT-07',100);
    INSERT INTO TEST VALUES('01-NOV-07',100);
    INSERT INTO TEST VALUES('01-DEC-07',100);
    INSERT INTO TEST VALUES('01-JAN-08',100);
    INSERT INTO TEST VALUES('01-FEB-08',100);
    INSERT INTO TEST VALUES('01-MAR-08',100);
    INSERT INTO TEST VALUES('01-APR-08',100);
    INSERT INTO TEST VALUES('01-MAY-08',100);
    INSERT INTO TEST VALUES('01-JUN-08',100);
    Ok so thats my test table, I want a query which will give me the sum of the field Amount grouping by Year but it should give me the sum of the month from July 06 till July 07. For Example if i put the Date Range from 2003 to 2006 then it should give me out put by group the year from july till next year jun.
    It should look something like this
    Year Amount
    07-2005/06-2006 5000
    07-2006/06-2007 2000
    07-2007/06-2008 1200
    Can i get a query which will group in the above manner???
    Thanks & Regards
    vihang

    SQL> select '07'||extract(year from add_months(month,-7))||
      2        '-07'||extract(year from add_months(month,5)) yr,
      3        sum(amount) amt
      4  from test
      5  group by '07'||extract(year from add_months(month,-7))||
      6        '-07'||extract(year from add_months(month,5));
    YR                                    AMT
    072007-072008                        1100
    072006-072007                        1200
    072005-072006                         500.
    Message was edited by:
            jeneesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help need to create a query

    I need to fetch records from a table. Please help me to create a query
    The Tablename is Employee. It has the following records
    Department Empname Gender
    Finance Tom Male
    Finance Rick Male
    Finance Stacy Female
    Corporate Tom Male
    Corporate Rob Male
    I want to select the value of the Gender field from the Employee table corresponding to a Department
    If all the values in the Gender field are 'MALE' corresponding to 'finance' in the Department field, the value should be 'MALE'
    If there is a value 'FEMALE', the gender corresponding to the Empname 'TOM' should be considered as the gender

    Tables have rows - not records.
    Your question is a basic SQL language question - which means you do not know the SQL language. This forum is not a classroom for teaching you the SQL language.
    Use the following as the basic outline of how your SQL language statement need to look like for selecting the required from the table:
    SELECT
      <<sql projection goes here>>
    FROM <<table name goes here>>
    WHERE <<filter conditions go here>>
    {code}
    The SQL projection specifies the list of columns the SQL need to return to the caller.
    The filter condition is basic predicates and AND and OR  can be used for multiple predicates.
    Go to http://tahiti.oracle.com and look for the +SQL Reference Guide+ for the Oracle version you are using. The +SELECT+ statement syntax is covered in detail and sample statements are provided.
    And please do not expect this forum to be used as a classroom, or expect this forum to do your homework for a class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help needed to tune the Query:Statistics added

    Can someone DBA please help me to tune this query:
    SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
    CASE
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    ELSE
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
    FROM
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN ('%')
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
    AND NVL(G.OFFICE_ID,0) IN ('%')
    AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
    ORDER BY PROFILE_NM
    The number of rows in these tables are as follows:
    PROFILE_PORTAL -- 2392
    TBL_BDA_AGENCY_RESP_REP 3508
    TBL_BDA_AGENCY_OFFICE 2151
    TBL_BDA_OFFICE 3
    USERS_PORTAL 270500
    TBL_BDA_USR_ISS_GRP 234
    TBL_BDA_ISS_GROUP 2
    ATTRIBUTE_VALUES_PORTAL 2790
    PROFILE_TYPE_PORTAL 3
    The Explain pal nhas given this o/p to me:
    SQL> select * from table(dbms_xplan.display) dual;
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
    | 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
    | 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
    |* 2 | FILTER | | | | | |
    |* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
    |* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
    |* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
    | 6 | NESTED LOOPS | | 7 | 805 | | 37 |
    | 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
    |* 8 | FILTER | | | | | |
    | 9 | NESTED LOOPS OUTER | | | | | |
    |* 10 | FILTER | | | | | |
    | 11 | NESTED LOOPS OUTER | | | | | |
    | 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
    |* 13 | HASH JOIN | | 3 | 120 | | 7 |
    |* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
    |* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
    |* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
    | 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
    |* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
    | 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
    |* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    | 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
    |* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
    |* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
    | 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
    | 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
    |* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
    |* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    Predicate Information (identified by operation id):
    2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
    AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
    3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
    4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
    5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
    8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
    10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
    13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
    14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
    NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
    15 - filter("L"."APPLICATION_CD"='BDA')
    16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
    18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
    20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
    22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
    23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
    26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
    27 - access("T"."AGENCY_ID"=:B1)
    Note: cpu costing is off
    57 rows selected.
    Elapsed: 00:00:01.08
    Please help me.
    Aashish S.

    Hello Eric,
    Here is the code:
    SELECT DISTINCT
    K.ATTRIBUTE_VALUE AGENCY_ID,
    B.PROFILE_NM ,
    NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
    f.OFFICE_ID,
    B.PROFILE_ID,
    '%' ROLE,
    '%' LAYOUT,
    case
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    else
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','&lt;a sbcuid_in=' || H.USERID || ' target=NEW &gt;'||H.FIRSTNAME || ' ' || H.LASTNAME ||
    '( ' || H.USERID || ' )&lt;/a&gt;' ) USER_NAME
    from
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS
    (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN (1)
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0))
    LIKE '%'
    OR NVL(B.PROFILE_ID,0) IN (1))
    AND NVL(G.OFFICE_ID,0) IN (1)
    AND (to_char(NVL(C.RESP_USR_ID,'0'))
    LIKE '%'
    OR NVL(C.RESP_USR_ID,'0') IN ('%'))
    ORDER BY PROFILE_NM
    This is the Query and the query takes some mins. to run in prod environment.
    From the Query plan ,I am not able to get any idea for optimization.
    Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
    Thanks.
    Aashish S.

  • Help needed in writing a query

    Hi all,
    Following is the structure of my table.
    Data
    Key Number
    Id Number
    Value varchar2(100)
    activity_name varchar2(100)
    Creation_Date Date
    Eval_Point varchar2(100)
    In the above table Id is the primary key.
    The column eval_point holds only two types of entries 'activation' or 'completion'
    The activity_name column holds the name of the activity.
    The sample entries in the table are as follows
    Key Value activity_name Creation_Date Id Eval_Point
    260002 XXX assign_1 2007-09-21 16:58:41.920000 951 activation
    260002     XXX assign_1 2007-09-21 16:58:43.392000 953     completion
    260002     XXX assign_2 2007-09-21 16:59:03.732000 956     activation
    260002     XXX assign_2 2007-09-21 16:59:04.112000 954     completion
    260002     XXX assign_3 2007-09-21 16:59:24.331000     958     activation
    260002     XXX assign_3 2007-09-21 16:59:24.421000     957     completion
    i need to write a query which gives me data in the following format
    value id start_date end_date
    XXX YYY 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000
    where start_date is the creation date of the 'activation' and end_date is the creation_date of 'completion'.
    Can somebody help?
    -thanks
    lavanya

    hello all,
    I would like to re frame my question.
    this is the output of the base query
    select id,instance_key,sensor_target,activity_sensor,creation_date,eval_point from bpel_variable_sensor_values where instance_key=260002;
    953     260002     Assign_1     952     2007-09-21 16:58:43.392000     completion
    951     260002     Assign_1     952     2007-09-21 16:58:41.920000     activation
    956     260002     Assign_2     955     2007-09-21 16:59:03.732000     activation
    954     260002     Assign_2     955     2007-09-21 16:59:04.112000     completion
    958     260002     Assign_3     959     2007-09-21 16:59:24.331000     activation
    957     260002     Assign_3     959     2007-09-21 16:59:24.421000     completion
    962     260002     Assign_4     960     2007-09-21 16:59:44.741000     completion
    961     260002     Assign_4     960     2007-09-21 16:59:44.640000     activation
    964     260002     Assign_5     965     2007-09-21 17:00:05.290000     completion
    963     260002     Assign_5     965     2007-09-21 17:00:04.950000     activation
    I am trying out this query
    select a.instance_key,a.creation_date,b.creation_date,a.id
    from bpel_variable_sensor_values a, bpel_variable_sensor_values b
    where a.instance_key=b.instance_key
    and a.instance_key=260002
    and a.eval_point='activation'
    and b.eval_point='completion'
    and i am getting 25 entries i.e a cartesian product of a.creation_date
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:58:43.392000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:04.112000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:24.421000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:44.741000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 17:00:05.290000     951
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:58:43.392000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:04.112000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:24.421000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:44.741000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 17:00:05.290000     956
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:58:43.392000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:04.112000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:24.421000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:44.741000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 17:00:05.290000     958
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:58:43.392000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:04.112000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:24.421000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:44.741000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 17:00:05.290000     961
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:58:43.392000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:04.112000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:24.421000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:44.741000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 17:00:05.290000     963
    can soembody help me to reduce these to 5 rows.

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • Help needed in Extending HeaderVO -VERY URGENT!!

    Hello,
    I need a urgent help.
    Actually I am trying to modify the exisiting Print Quote Document which is actually getting called from a template cald ASOPRINTQUOTE.xsl
    This particular xsl uses HeaderVO, LinesVO and PromptVO and hence I had to modify these xml and in turn the .java files.
    I customized it by adding the new columns thru JDeveloper and extending the VO's and substituting them
    In the process while extending the respective VO's comes a step wherein I need to specify(Thru JDeveloper) Application Short Name and Responsibility Key.
    Now the issue is this particular Quote dicument can be accessed from 2 different respons. called
    Oracle HTML Order Quoting Sales Agent(Its a OA framework with application top as QOT)
    & Quoting Sales Agent.(Its form based with Application top as ASO)
    I chose ASO as the top as all my .class files and .xml files are present in
    oracle/apps/aso/print/server
    Now then after extending the VO's and importing it etc . when I log in thru the reponsibilty
    Oracle HTML Order Quoting Sales Agent , it gets me a error of stmt exception.
    wheras
    it runs via the respon Quoting Sales Agent and reproduces a PDF output without any data??
    There are few questions I am looking out for an answer desperately.
    1) My HeaderVO, LinesVO and PromptVO are extended, so do i need to extend the links present in that in my new extended VO' s as well.
    2) My xsl stylesheet has a statement as
    select values of:....../HeaderVO/HeaderRow/....etc etc
    do i need to replace the above line to my new extended VO i.e
    select values of:....../CustHeaderVO/HeaderRow/...etc etc
    Kindly reply to me asap as I am in a development scenario..
    Do let me kow if u need more clarity on this?
    Regards,
    Ajit

    Oracle quoting is not in OAF, only the print functionality uses these VOs as data source , and are used in the xsl, for XML publisher to generate the quote print .
    1) My HeaderVO, LinesVO and PromptVO are extended, so do i need to extend the links present in that in my new extended VO' s as well.
    Please explain this , what do you mean by extending links ?2) My xsl stylesheet has a statement as
    select values of:....../HeaderVO/HeaderRow/....etc etc
    do i need to replace the above line to my new extended VO i.e
    select values of:....../CustHeaderVO/HeaderRow/...etc etc
    YesThanks
    Tapash

  • Immediate help needed for Forms on Citrix

    All Gurus
    Form works perfect on desktop but when I put in on citrix then it didn't work. problem is when we click on any push button that is not executing a code behind it. so push button in forms are not working. we installed forms 6i runtime software on citrix. is there anything do I need to do to make buttons work.
    Thank you so much
    Nitin

    I compiled my form on desktop and its working fine then I moved .fmx file to citrix and there button is not working. other thing using forms default menu if I use execute query it works but when I click on button (when-button pressed trigger and code is go_block, execute_query) then it doesn't execute. so I added just message for testing and message also not populating. so what would be the issue?
    where you are saying I have to compile form on citrix and how we can compile on citrix? pl. help.
    do you have forms installed on citrix?
    pl.help
    Thanks
    Nitin

  • Help needed in tuning this query

    This is the SQL i would like to tune for performace...
    The table structure is given below.
    The table has about 2 million rows.
    From the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 50% will have THAMES_URN_WITH_ROLE_SUFFIX as 'TP%'. At present there are unique and primary key indexes on THAMES_URN_WITH_ROLE_SUFFIX .
    I'm sure that we need a b-tree index on STG_UPDATE_DATE_TIME as it is the column with good selectivity.
    I'm primarily concerned about the substr, instr and reverese on THAMES_URN_WITH_ROLE_SUFFIX.
    Also pls. let me know if the order of predicates is right.
    Thanks in advance.
    SELECT TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN, TPD_STG_TL_SF_LEGAL_OWNER.UPDATE_SOURCE, TPD_STG_TL_SF_LEGAL_OWNER.SOURCE_EXTRACT_DATE_TIME, TPD_STG_TL_SF_LEGAL_OWNER.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_SF_LEGAL_OWNER.CONTACTABLE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.BANKRUPTCY_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ASSIGNED_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.IN_TRUST_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.DIVORCE_CASE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.POA_COP_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.CLEANSING_STATUS, TPD_STG_TL_SF_LEGAL_OWNER.CATEGORY
    FROM
    TPD_STG_TL_SF_LEGAL_OWNER
    WHERE
    ((TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME > '$$Load_Start_Time'
    AND
    TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME <= '$$Load_End_Time')
    OR
    (TPD_STG_TL_SF_LEGAL_OWNER.TPDB_PROCESSED_IDENTIFIER != 'Y') )
    AND
    SUBSTR(TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX,1,2)='TP'
    AND
    SUBSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),INSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),'-',1)-1,1)!='S'
    ========================================
    CREATE TABLE TPD_STG_TL_SF_LEGAL_OWNER
    THAMES_URN VARCHAR2(35 BYTE) NOT NULL,
    UPDATE_SOURCE VARCHAR2(3 BYTE),
    SOURCE_EXTRACT_DATE_TIME DATE,
    LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
    CONTACTABLE_INDICATOR CHAR(1 BYTE),
    ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
    BANKRUPTCY_INDICATOR CHAR(1 BYTE),
    ASSIGNED_INDICATOR CHAR(1 BYTE),
    IN_TRUST_INDICATOR CHAR(1 BYTE),
    DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
    POA_COP_INDICATOR CHAR(1 BYTE),
    THAMES_URN_WITH_ROLE_SUFFIX VARCHAR2(39 BYTE),
    THAMES_LEGAL_OWNERSHIP_IND CHAR(1 BYTE),
    PRODUCT_HOLDING_ROLE_TYPE VARCHAR2(21 BYTE),
    OWNERSHIP_SPLIT_PERCENTAGE NUMBER(3),
    SOURCE_SYSTEM VARCHAR2(3 BYTE),
    TITLE VARCHAR2(50 BYTE),
    FIRST_NAME VARCHAR2(50 BYTE),
    MIDDLE_INITIAL VARCHAR2(50 BYTE),
    SURNAME VARCHAR2(50 BYTE),
    GENDER CHAR(1 BYTE),
    BIRTH_DATE DATE,
    DEATH_INDICATOR CHAR(1 BYTE),
    DEATH_RECORD_DATE DATE,
    NATIONAL_INSURANCE_NUMBER VARCHAR2(9 BYTE),
    GONE_AWAY_INDICATOR CHAR(1 BYTE),
    ADDRESS_LINE_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_3 VARCHAR2(50 BYTE),
    ADDRESS_LINE_4 VARCHAR2(50 BYTE),
    ADDRESS_LINE_5 VARCHAR2(50 BYTE),
    POST_CODE VARCHAR2(12 BYTE),
    COUNTRY VARCHAR2(50 BYTE),
    OVERSEAS_ADDRESS_INDICATOR CHAR(1 BYTE),
    ORGANISATION_NAME VARCHAR2(50 BYTE),
    TPDB_PROCESSED_IDENTIFIER CHAR(2 BYTE),
    CLEANSING_STATUS VARCHAR2(30 BYTE),
    CATEGORY VARCHAR2(50 BYTE),
    SCHEME_NAME VARCHAR2(50 BYTE),
    STG_CREATE_DATE_TIME DATE,
    STG_UPDATE_DATE_TIME DATE,
    LAST_UPDATED_DATE_TIME DATE
    TABLESPACE TPDBS01A_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE UNIQUE INDEX TPD_STG_TL_SF_LEGAL_OWNER_PK ON TPD_STG_TL_SF_LEGAL_OWNER
    (THAMES_URN_WITH_ROLE_SUFFIX)
    LOGGING
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    NOPARALLEL;
    ALTER TABLE TPD_STG_TL_SF_LEGAL_OWNER ADD (
    CONSTRAINT TPD_STG_TL_SF_LEGAL_OWNER_PK
    PRIMARY KEY
    (THAMES_URN_WITH_ROLE_SUFFIX)
    USING INDEX
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    ));

    > If indexes don't help, is the only way to gain REAL
    performance gain on this type of query is to
    partition the table
    If a Full Table Scan on a table takes "too long" (and
    this is purely subjective - "too long" is different
    for every problem) and indexes can't help, and we
    need <100% of the rows, and if partitioning will give
    us the performance we desire, is it OK do it ? Also
    would STG_UPDATE_DATE_TIME be the best column to do a
    index partion ?
    For this type of query, partitioning on STG_UPDATE_DATE_TIME would be good.
    However, partitioning is not done just for one query. It has to fit in your total design. For example, if you are also doing queries with a predicate like <column with a local unique index but not the partition key> = <constant>, it would have to visit all partitions instead of just one, and those queries would take much longer to execute. You can make the index global, but there all kind of maintenance issues with that. In short: be careful about partitioning and think it through first.
    > But is it a good option to partition tables with
    total no. of rows between 2 million and 5 million ? I
    thought partitioning is better done for tables > 20
    million.
    Please throw some light on that.
    Generally, partitioning is done on bigger tables, yes. But it is not about some specific number of rows. You partition a table when all forecasted use of the table is known, so you can make a good judgement which usages will benefit, which ones won't be affected and which ones are likely to suffer. When the benefits outweigh the disadvantages, you partition...
    Above I had an example about queries that are going to suffer. Partitioning is beneficial for example when once in some period you'd have to delete A LOT of old rows. Or when you have some data warehousing queries that need like 10% of only the most recent data in a huge table.
    The decision is yours.
    Regards,
    Rob.

  • Help needed  in writing a Query/Procedure

    Hello All,
    Need all ur help in writing a query or procedure
    Lets say the Table name is DEMO
    There i have one column like num it has values
    1
    2
    3
    4
    5
    8
    9
    10
    my query output should be
    1-5
    8-10
    i,e .. if the diff between two rows is greater than 1 then it result should be in a separate group
    I need a query/Procedure for this. Kindly help
    Regards,
    Chandra

    Tried obtaining the output using SQL and the result is as follows:
    SQL> WITH T AS
      2  (
      3  SELECT 1 COL1 FROM DUAL
      4  UNION
      5  SELECT 2 COL1 FROM DUAL
      6  UNION
      7  SELECT 3 COL1 FROM DUAL
      8  UNION
      9  SELECT 4 COL1 FROM DUAL
    10  UNION
    11  SELECT 5 COL1 FROM DUAL
    12  UNION
    13  SELECT 8 COL1 FROM DUAL
    14  UNION
    15  SELECT 9 COL1 FROM DUAL
    16  UNION
    17  SELECT 10 COL1 FROM DUAL
    18  UNION
    19  SELECT 13 COL1 FROM DUAL
    20  UNION
    21  SELECT 14 COL1 FROM DUAL
    22  UNION
    23  SELECT 15 COL1 FROM DUAL
    24  UNION
    25  SELECT 16 COL1 FROM DUAL
    26  UNION
    27  SELECT 23 COL1 FROM DUAL
    28  UNION
    29  SELECT 24 COL1 FROM DUAL
    30  )
    31  SELECT OUTPUT FROM
    32  (
    33  SELECT DECODE(COL3,NULL,COL1, COL2)  || '-' || LEAD(DECODE(COL3,NULL,COL3, COL1)) OVER (ORDER BY DECODE(COL3,NULL,COL1, COL2)) OUTPUT  FROM
    34  (
    35  SELECT COL1, LEAD(COL1) OVER (ORDER BY COL1) COL2, LAG(COL1) OVER (ORDER BY COL1) COL3 FROM T
    36  )
    37  WHERE
    38  (COL2 - COL1 > 1 OR COL2 IS NULL OR COL3 IS NULL)
    39  )
    40  WHERE OUTPUT != '-';
    OUTPUT                                                                         
    1-5                                                                            
    8-10                                                                           
    13-16                                                                          
    23-24

  • Help needed in tuning a query

    Hi,
    I need some help in performing tuning of a big query. Explain plan is as under:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    Edited by: AbdulHadi on Sep 16, 2011 3:56 PM
    Edited by: AHadi on Sep 19, 2011 10:02 AM

    3     SORT GROUP BY          47916     25M     491G     15M (3)     17:30:31               
    4     VIEW          870M     445G          15M (2)     17:24:08               
    5     HASH GROUP BY          870M     427G     885G     15M (2)     17:24:08               
    In above steps its using very high temporary tablespace usage. please try to tune your query.
    - dynamic sampling used for this statement
    The statistics appears to be stale.

  • Help needed in Form userexit_save_document_prepare include MV45AFZZ

    Hi Experts,
    I need to check the values entered in table control under sales tab in VA01.
    If the item category for a material is 'TANN' it should save if not it should not save and display an error message and then it should alow the user to edit the table control values. 
    how do i achieve it in Form userexit_save_document_prepare include MV45AFZZ.
    this is what I have done. kindly check the logic and help me further.
    case sy-ucomm.
    when 'SICH'.          " On Save action
    if vbak-vtweg eq 'HA'.  " Check Distribution channel
      flg_dh = 'X'.         " Sets if DC is 'HA'.
    endif.
    if flg_dh eq 'X'.
      if vbap-pstyv eq 'TANN'.    " Check item category
        flg_itmc = 'X'.            " Set if item cat is 'TANN'.
      else.
      message 'SO could not be created Please enter brokerage material' type 'E'.
      endif.

    Hi,
    Please use the following:
    when 'SICH'.          " On Save action
    if vbak-vtweg eq 'HA'.  " Check Distribution channel
      flg_dh = 'X'.         " Sets if DC is 'HA'.
    endif.
    if flg_dh eq 'X'.
      if vbap-pstyv eq 'TANN'.    " Check item category
        flg_itmc = 'X'.            " Set if item cat is 'TANN'.
      else.
      message 'SO could not be created Please enter brokerage material' type 'E' display like 'E'.
      endif.
    endif.

  • Need clarification on select query Urgent!!!!!

    Hi ,
    i want clarification about this query , because i want improve performence to report in ST05 it is showing 1,40,250 time so i need to do some thing on this please any body help me out.
    SELECT  matnr  werks  dispo
                 FROM   marc
                 INTO   TABLE  it_marc
                        WHERE  matnr  IN  s_matnr  AND
                               werks  IN  s_werks  AND
                               dispo  EQ  p_dispo.
        DESCRIBE TABLE it_marc  LINES w_lines.
        IF  w_lines  IS INITIAL.
          MESSAGE e518(zv) WITH p_dispo.
        ENDIF.
      ENDIF.
    thanks,
    murali.

    SELECT matnr
      FROM mara
      INTO TABLE it_mara
      WHERE matnr IN s_matnr.
    IF sy-subrc eq 0.
      SELECT matnr werks dispo
        FROM marc
        INTO TABLE it_marc
        FOR ALL ENTRIES IN it_mara
        WHERE matnr = it_mara-matnr
          AND werks IN s_werks
          AND dispo EQ p_dispo.
      DESCRIBE TABLE it_marc LINES w_lines.
      IF w_lines IS INITIAL.
        MESSAGE e518(zv) WITH p_dispo.
      ENDIF.
    ENDIF.
    I am sorry, but I comment also bad recommendations, if I find any. And the above example such
    a bad recommendation.
    SELECT matnr
      FROM mara
      INTO TABLE it_mara
      WHERE matnr IN s_matnr.
    The first select selects much more than you really need, while there is only a select single necessary.
      DESCRIBE TABLE it_marc LINES w_lines.
      IF w_lines IS INITIAL.
    It is also not necessary to count 1000 of lines, if you want to know whether there was at least one records, a check
    of a sy-subrc is much better. This should also be done in the original coding.
    As said above, check what is in s_matnr and s_werks and what is suppossed to come back.
    Siegfried

Maybe you are looking for

  • Does my iphone 5 US warranty valid in India ..?

    i purchased iphone 5  (factory unlocked )From amazon in portland a month before and m using it in India  and my iphone got a problem of flickering screen and m not able to operate this iphone ...amazon provided me a purchased bill and i think it is i

  • Creating a flag based formula for Dimension

    Greetings everyone, Hopefully this is simple answer.  I have two dimensions "A" and "B" and a measure "C", where "B" is many to one attribute of "A", I would like to create a Flag formula in context that can characterise if a certain attribue of "B"

  • HT1766 Icloud backup fail

    Icloud backup failed yet again.  There are several questions out there about this problem, and I have done all of the suggestions including turning off phone, resetting network settings, deleting icloud account and re-installing/delete old backups. 

  • Missing reminders in Outlook 2007

    Hi, We have had Outlook operating with reminders for the last 6 months with no complaints until recently.  Reminders have disappeared.  I have deleted appointments and re installed, still no reminders.  I have added a appointment and reminders pop up

  • How to get last slide to stay on screen?

    How do I get the text on my last slide to stay on screen indefinitely? I've got my project preferences set to not fade out on last slide, but the screen goes blank when I get to the end of my timeline. Any ideas? Do I have to set an invisible click b