Need help - sql query

Hi,
     I have two tables(production & sales). I want to generate monthly statement. The followings are the sample data.
PRODUCTION:
DATE          MATERIAL     WEIGHT      AMOUNT
01/12/2008     Item1     300     6000
03/12/2008     item2          250      3500
07/12/2008     item3          700     6500
12/12/2008     item1          200     4000
20/12/2008     item3          400     9600
25/12/2008     item1          250     5000
Sales:
SAL_Date          Sal_Material     sal_weight     SAL_Amount
12/12/2008     item3          270     2300
15/12/2008     item1          200     4000
20/12/2008     item2          250     3500
20/12/2008     item1          100     2000
23/12/2008     item1          100     2000
27/12/2008     item3          200     3500
I want to generate monthly statement like the following....
Required Report:
Date          Production          Sales
          Weight - Amount      Weight - Amount          
01/12/2008     300     6000          0     0
02/12/2008     0     0     0     0
03/12/2008     250     3500          0     0           
04/12/2008     0 0 0 0
07/12/2008     700 6500 0 0
12/12/2008     200     4000     270 2300
31/12/2008 0 0 0 0
i don't know, how to generate sequential date...
Could you please tell me the query?
Thanks & Regards

SQL> with prod
  2  as
  3  (
  4     select to_date('01/12/2008','dd/mm/yyyy') dt, 'Item1' material, 300 weight, 6000 amount from dual union all
  5     select to_date('03/12/2008','dd/mm/yyyy'), 'item2', 250, 3500 from dual union all
  6     select to_date('07/12/2008','dd/mm/yyyy'), 'item3', 700, 6500 from dual union all
  7     select to_date('12/12/2008','dd/mm/yyyy'), 'item1', 200, 4000 from dual union all
  8     select to_date('20/12/2008','dd/mm/yyyy'), 'item3', 400, 9600 from dual union all
  9     select to_date('25/12/2008','dd/mm/yyyy'), 'item1', 250, 5000 from dual
10  ), sales
11  as
12  (
13     select to_date('12/12/2008','dd/mm/yyyy') dt, 'item3' material, 270 weight, 2300 amount from dual union all
14     select to_date('15/12/2008','dd/mm/yyyy'), 'item1', 200, 4000 from dual union all
15     select to_date('20/12/2008','dd/mm/yyyy'), 'item2', 250, 3500 from dual union all
16     select to_date('20/12/2008','dd/mm/yyyy'), 'item1', 100, 2000 from dual union all
17     select to_date('23/12/2008','dd/mm/yyyy'), 'item1', 100, 2000 from dual union all
18     select to_date('27/12/2008','dd/mm/yyyy'), 'item3', 200, 3500 from dual
19  ),find_date
20  as
21  (
22     select dt st, last_day(dt) ed
23       from (select distinct trunc(dt,'month') dt from prod
24             union
25             select distinct trunc(dt,'month') dt from sales)
26  ),day_list
27  as
28  (
29     select (level-1)+st dt
30       from find_date
31     connect by level <= (ed - st)+1
32  )
33  select d.dt, t.p_weight, t.p_amount, t.s_weight, t.s_amount
34    from day_list d
35    left join
36         (select decode(p.dt,null,s.dt,p.dt) dt,
37                    sum(p.weight) p_weight, sum(p.amount) p_amount, sum(s.weight) s_weight, sum(s.amount) s_amount
38            from prod p
39            full outer join sales s
40              on p.dt = s.dt
41             and p.material = s.material
42           group by decode(p.dt,null,s.dt,p.dt)) t
43      on d.dt = t.dt
44  order by d.dt
45  /
DT          P_WEIGHT   P_AMOUNT   S_WEIGHT   S_AMOUNT
01-DEC-08        300       6000
02-DEC-08
03-DEC-08        250       3500
04-DEC-08
05-DEC-08
06-DEC-08
07-DEC-08        700       6500
08-DEC-08
09-DEC-08
10-DEC-08
11-DEC-08
DT          P_WEIGHT   P_AMOUNT   S_WEIGHT   S_AMOUNT
12-DEC-08        200       4000        270       2300
13-DEC-08
14-DEC-08
15-DEC-08                              200       4000
16-DEC-08
17-DEC-08
18-DEC-08
19-DEC-08
20-DEC-08        400       9600        350       5500
21-DEC-08
22-DEC-08
DT          P_WEIGHT   P_AMOUNT   S_WEIGHT   S_AMOUNT
23-DEC-08                              100       2000
24-DEC-08
25-DEC-08        250       5000
26-DEC-08
27-DEC-08                              200       3500
28-DEC-08
29-DEC-08
30-DEC-08
31-DEC-08
31 rows selected.

Similar Messages

  • Need Help to query Lync Database for User Information

    Need Help to Query the lync database to retrieve below user information.
    1. SIP Address of the registered user
            2. Phone Number configured to the particular account.
            3. IP Address
           4. Last Logged in time.
    I am trying to pull the above information from rtc database for all the registered users. Please let me know if this is possible and it would be great if you can throw some light on what tables to look for the data. Thank You.

    Hi,
    For SIP address and Phone number you can check RTC database.
    IP Address:
    You can refer to the link below to query IP address: 
    http://h30499.www3.hp.com/t5/Business-Service-Management-BAC/Monitoring-Lync-with-the-User-Registrations-Viewer-Free-NMC-tool/ba-p/5961497#.UtOU43mIrwo
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
    Last Logged in time:
    You can refer to the link below:
    http://blogs.technet.com/b/dodeitte/archive/2011/05/11/how-to-get-the-last-time-a-user-registered-with-a-front-end.aspx
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support

  • Need help-SQL with result format suppressing duplicate values

    I am trying to write a SQL which would select data from the below tables(in reality i have many other tables also) but I wanted to know how do i get the data in the format given below.
    The scenario is :-A training_plan can N no. of OBJECTIVES and EACH objective has N no.of activities
    Insert into TEST_TRAINING_PLAN
       (TPLAN_ID, TPLAN_NAME, TPLAN_DESC, T_PERSON_ID
    Values
       ('111', 'test_name', 'test_name_desc', '****')
    Objectives table:-
    Insert into TEST_TRAINING_OBJECTIVE
       (T_OBJECTIVE_ID,  T_OBJECTIVE_NAME,T_owner)
    Values
       ('10', 'objective1', '1862188559')
    Objective and Training Plan relationship table where TPLAN_ID is the foreign key.
    Insert into TEST_TP_OBJECTIVE
       (TPLAN_TOBJ_ID, TPLAN_ID, T_OBJECTIVE_ID, 
        REQUIRED_CREDITS)
    Values
       ('1', '111', '10',5)
    Objective and Activity relationship table where T_OBJECTIVE_ID is the foreign key from the TEST_TRAINING_OBJECTIVE table.
    Insert into TEST_TRAIN_OBJ_ACTIVITY
       (TOBJ_TRAIN_ACTIVITY, T_OBJECTIVE_ID, ACTIVITY_ID, IS_REQUIRED, STATUS,
        ACTIVITY_TYPE, ITEM_ORDER, IS_PREFERRED)
    Values
       ('1000', '10', 'selfstudy event', SS1, NULL,
        'Event', 0, 0);
    Insert into TEST_TRAIN_OBJ_ACTIVITY
       (TOBJ_TRAIN_ACTIVITY, T_OBJECTIVE_ID, ACTIVITY_ID, IS_REQUIRED, STATUS,
        ACTIVITY_TYPE, ITEM_ORDER, IS_PREFERRED)
    Values
       ('1001', '10', 'SQLcourse', 1, NULL,
        'Course', 1, 0);
    Insert into TEST_TRAIN_OBJ_ACTIVITY
       (TOBJ_TRAIN_ACTIVITY, T_OBJECTIVE_ID, ACTIVITY_ID, IS_REQUIRED, STATUS,
        ACTIVITY_TYPE, ITEM_ORDER, IS_PREFERRED)
    Values
       ('1002', '10', 'testSQL', 1, NULL,
        'test', 2, 0);
    COMMIT;
    firstname     emplid     Tplan name     Number of activities/credits completed(for TP)     Objective Name     Number of required activities/Credits (for objective)     Number of activities/credits completed(for objective)     activity  name     activity completion status
    U1     U1     TP1     5                         
                        OBJ1     4     3     C1     PASSED
                                       C2     PASSED
                                       C3     WAIVED
                                       T1     ENROLLED
                                       T2     ENROLLED
                        OBJ2     3     2          
                                       S1     ENROLLED
                                       S2     PASSED
                                       T3     WAIVED
    U1     U1     TP2                         C4     INPROGRESS
                   50     OBJ11     50     30     C11     PASSED
    **The second row where we have another training_plan record and accordingly all objectivesand their objective.**similarly ,i need to display many Training_plan records in such tabular format.Please help with the SQL query to select and display data in the above format
    If you want to suppress duplicate values in some of your results columns
    I am using toad 9.1 using Oracle 10g version 2

    Hi,
    You can use the BREAK command to suppress duplicate values.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12009.htm#SQPUG030
    (scroll down for an example)
    It's a 'SQL*Plus-ism', not sure if TOAD's capable to handle it.
    Simple example:
    HR%xe> break on department_name
    HR%xe> select l.department_name
      2  ,        e.last_name
      3  ,        e.first_name
      4  from     departments l
      5  ,        employees e
      6  where    e.department_id = l.department_id;
    DEPARTMENT_NAME                LAST_NAME                 FIRST_NAME
    Executive                      King                      Steven
                                   Kochhar                   Neena
                                   De Haan                   Lex
    IT                             Hunold                    Alexander
                                   Ernst                     Bruce
                                   Austin                    David
                                   Pataballa                 Valli
                                   Lorentz                   Diana
    Finance                        Greenberg                 Nancy
                                   Faviet                    Daniel
                                   Chen                      John
                                   Sciarra                   Ismael
                                   Urman                     Jose Manuel
                                   Popp                      Luis
    Purchasing                     Raphaely                  Den
                                   Khoo                      Alexander
                                   Baida                     Shelli
                                   Tobias                    Sigal
                                   Himuro                    Guy
                                   Colmenares                Karen
    Shipping                       Weiss                     Matthew
                                   Fripp                     Adam
                                   Kaufling                  Payam
                                   Vollman                   Shanta
                                   Mourgos                   Kevin
                                   Nayer                     Julia
                                   Mikkilineni               Irene
                                   Landry                    James
    Public Relations               Baer                      Hermann
    Accounting                     Higgins                   Shelley
                                   Gietz                     William
    106 rijen zijn geselecteerd.

  • Need help with query joining several tables into a single return line

    what i have:
    tableA:
    puid, task
    id0, task0
    id1, task1
    id2, task2
    tableB:
    puid, seq, state
    id0, 0, foo
    id0, 1, bar
    id0, 2, me
    id1, 0, foo
    id2, 0, foo
    id2, 1, bar
    tableC:
    puid, seq, date
    id0, 0, 12/21
    id0, 1, 12/22
    id0, 2, 12/22
    id1, 0, 12/23
    id2, 0, 12/22
    id2, 1, 12/23
    what i'd like to return:
    id0, task0, 12/21, 12/22, 12/22
    id1, task1, 12/23, N/A, N/A
    id2, task2, 12/22, 12/23, N/A
    N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
    id0, task0, 12/21
    id0, task0, 12/22
    id0, task0, 12/23
    id1, task1, 12/23
    is this possible fairly easily?
    Edited by: user9979830 on Mar 29, 2011 10:53 AM
    Edited by: user9979830 on Mar 29, 2011 10:58 AM

    Hi,
    Welcome to the forum!
    user9979830 wrote:
    what i have:...Thanks for posting that so clearly!
    Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
    CREATE TABLE     tablea
    (       puid     VARCHAR2 (5)
    ,     task     VARCHAR2 (5)
    INSERT INTO tablea (puid, task) VALUES ('id0',  'task0');
    INSERT INTO tablea (puid, task) VALUES ('id1',  'task1');
    INSERT INTO tablea (puid, task) VALUES ('id2',  'task2');
    CREATE TABLE     tablec
    (       puid     VARCHAR2 (5)
    ,     seq     NUMBER (3)
    ,     dt     DATE          -- DATE is not a good column name
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  0,  DATE '2010-12-21');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  1,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  2,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id1',  0,  DATE '2010-12-23');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  0,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  1,  DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
    It doesn't look like tableb plays any role in this problem, so I didn't post it.
    Explain how you get the results from that data. For example, why do you want this row in the results:
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/21/2010 12/22/2010 12/22/2010rather than, say
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
    Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
    WITH     got_r_num     AS
         SELECT     puid
         ,     dt
         ,     ROW_NUMBER () OVER ( PARTITION BY  puid
                                   ORDER BY          seq          -- and/or dt
                           )         AS r_num
         FROM    tablec
    --     WHERE     ...     -- If you need any filtering, put it here
    SELECT       a.puid
    ,       a.task
    ,       MIN (CASE WHEN r.r_num = 1 THEN r.dt END)     AS dt1
    ,       MIN (CASE WHEN r.r_num = 2 THEN r.dt END)     AS dt2
    ,       MIN (CASE WHEN r.r_num = 3 THEN r.dt END)     AS dt3
    ,       MIN (CASE WHEN r.r_num = 4 THEN r.dt END)     AS dt4
    FROM       tablea    a
    JOIN       got_r_num r  ON   a.puid  = r.puid
    GROUP BY  a.puid
    ,            a.task
    ORDER BY  a.puid
    ;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
    This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
    Here's the output I got from the query above:
    PUID  TASK  DT1        DT2        DT3        DT4
    id0   task0 12/21/2010 12/22/2010 12/22/2010
    id1   task1 12/23/2010
    id2   task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
    If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
    If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
    There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
    For various ways to deal with a variable number of pivoted coolumns, see the following thread:
    PL/SQL
    This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
    PL/SQL
    If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one.

  • Need a SQL Query (URGENT)

    Hi Folks,
    I have 2 tables, in which the 1st one has 200 columns and 2 table had 2 columns.. There is one common column for both the tables, but there is little change in schema of the tables...The common col in 2nd table is a primary key but the same column in the 1st table is a ordinary one..The data type for the common column is same...
    Now i need to write a query to select 199columns(except the common column)from the 1st table and the other column(2nd col)other than the common column frm the 2nd table for "table1.commoncolumn=table2.commoncolumn"......
    I had tried the natural join but its nt working in my informix sql database....I also tried by explicitly mentioning column names like "select column1,column2....column199,table2.column2 from table1,table2 where table1.commoncolumn=table2.commoncolumn", but its having a severe performance impact.......
    Can some please suggest a query for the above one?? Thankx in advance..

    Please gimme possible solutions & suggestions regarding the above query....
    The informix z forum very slow...The problem is, you labeled your questions badly. As this is a forum of volunteers people tend to react badly to the use of the word "urgent" in the subject line. Nobody's question matters more than anybody else's. In fact some regulars won't answer questions with "urgent" in the strapline as a matter of principle.
    Then when we get to actually read your question it turns out to be a question about Informix. I guess not many people here use Informix so your potential pool of responders is pretty small (for instance I'm not even sure how to spell it).
    It's not our fault the Informix forums are so lame.
    Anyway, what I suggest is you repost your question with a new title: (Off topic) Need help with an INFORMIX query.
    At least that will attract people who might be able to answer your question. Then you need to include the actual query you're running and all the supporting details necessary for people to understand the nature of the performance impact.
    You need to ask the right people and you need to ask the right question. This is standard etiquette (and indeed common sense) regardless of which forum you're using.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Need help with Query

    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE  FSYR      YTD_AMT
    A123            11          100  
    A456            11          200
    A123            10          50
    A456            10          100I want the output to look like this:
    ACCT_CODE     CURRENT_YEAR(11)       PRIOR_YEAR(10)
    A123               100                              50
    A456               200                              100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!
    Edited by: user5737516 on Jun 29, 2011 6:48 AM
    Edited by: user5737516 on Jun 29, 2011 6:50 AM

    user5737516 wrote:
    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE FSYR YTD_AMT
    A123 11 100
    A456 11 200
    A123 10 50
    A456 10 100
    I want the output to look like this:
    ACCT_CODE CURRENT_YEAR PRIOR_YEAR
    A123 100 50
    A456 200 100
    The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!what is prior year?

  • Need help in query tuning

    Hi All,
    In my application I have 3 tables. Event(1.2 L records), KeyWord(1K records) and Event_KeyWord_Mapping(1.4 L records) table.
    In my query i need to sort the Events table by 3 columns -( 1 Date column and 2 String column) and i am interested only in top 40 records.
    Below is the example query.
    select
        from
            (    select
                      a.*,
                ROWNUM    
            from
                (    select
                    distinct event_id   
                from
                    (     select
                        (this_.EVENT_ID),
                        this_.EVENT_GMT_DATE ,
                        this_.PRIORITY    
                    from
                        EVENTS this_,
                        event_keyword_mapping ekp 
                    where
                        this_.EVENT_ID = ekp.event_id
                        AND  ekp.keyword_id IN (
                            1643,2278,24,1090,2422,401 )
                        AND (
                                EVENT_CODE = 'IEP'
                                AND (
                                    IS_SCALL = 'Y'
                                    AND  COUNTRY_DISPLAY IN (
                                        'US','CA','UK','BE','FR','DE','IT','JP','AU','CH','EU'
                        OR (
                                EVENT_CODE = 'ICC'
                                AND IS_GTINDEX = 'Y'
                        AND  FX_EVENT = 'N' 
                        AND  EVENT_GMT_DATE BETWEEN to_date('12/27/2011 05:14:00','mm/dd/yyyy HH24:MI:SS')and
    to_date('03/27/2012 10:28:44','mm/dd/yyyy HH24:MI:SS')
                    ORDER BY
                        EVENT_GMT_DATE ASC  ,
                        PRIORITY ASC  ,
                        EVENT_ID ASC )) a 
                where
                    ROWNUM<=41)(1643,2278,24,1090,2422,401) keywords have 90K+ mappings.
    Below is the explain plan for the above query.
    | Id  | Operation                               | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                         
    |   0 | SELECT STATEMENT                        |                                |    41 |  1066 |       |   629K (85)| 02:05:51 |                                                                                                                                                                         
    |   1 |  VIEW                                   |                                |    41 |  1066 |       |   629K (85)| 02:05:51 |                                                                                                                                                                         
    |*  2 |   COUNT STOPKEY                         |                                |       |       |       |            |          |                                                                                                                                                                         
    |   3 |    VIEW                                 |                                | 25738 |   326K|       |   629K (85)| 02:05:51 |                                                                                                                                                                         
    |*  4 |     SORT GROUP BY STOPKEY               |                                | 25738 |   955K|  6929M|   629K  (2)| 02:05:51 |                                                                                                                                                                         
    |   5 |      CONCATENATION                      |                                |       |       |       |            |          |                                                                                                                                                                         
    |   6 |       MERGE JOIN CARTESIAN              |                                |   150M|  5463M|       | 96245   (2)| 00:19:15 |                                                                                                                                                                         
    |   7 |        TABLE ACCESS BY INDEX ROWID      | EVENTS                         |  1132 | 32828 |       |  1618   (1)| 00:00:20 |                                                                                                                                                                         
    |   8 |         BITMAP CONVERSION TO ROWIDS     |                                |       |       |       |            |          |                                                                                                                                                                         
    |   9 |          BITMAP AND                     |                                |       |       |       |            |          |                                                                                                                                                                         
    |  10 |           BITMAP CONVERSION FROM ROWIDS |                                |       |       |       |            |          |                                                                                                                                                                         
    |  11 |            SORT ORDER BY                |                                |       |       |       |            |          |                                                                                                                                                                         
    |* 12 |             INDEX RANGE SCAN            | EVT_PRIORITY_GMT_DATE_ID_INDEX | 30402 |       |       |    68   (0)| 00:00:01 |                                                                                                                                                                         
    |  13 |           BITMAP CONVERSION FROM ROWIDS |                                |       |       |       |            |          |                                                                                                                                                                         
    |* 14 |            INDEX RANGE SCAN             | EVENT_CODE_INDEX               | 30402 |       |       |    79   (0)| 00:00:01 |                                                                                                                                                                         
    |  15 |           BITMAP CONVERSION FROM ROWIDS |                                |       |       |       |            |          |                                                                                                                                                                         
    |* 16 |            INDEX RANGE SCAN             | FX_EVENT_INDEX                 | 30402 |       |       |   102   (1)| 00:00:02 |                                                                                                                                                                         
    |  17 |           BITMAP CONVERSION FROM ROWIDS |                                |       |       |       |            |          |                                                                                                                                                                         
    |* 18 |            INDEX RANGE SCAN             | IS_GTINDEX_INDEX               | 30402 |       |       |   102   (1)| 00:00:02 |                                                                                                                                                                         
    |  19 |        BUFFER SORT                      |                                |   133K|  1170K|       | 94627   (2)| 00:18:56 |                                                                                                                                                                         
    |  20 |         TABLE ACCESS FULL               | EVENT_KEYWORD_MAPPING          |   133K|  1170K|       |    84   (3)| 00:00:02 |                                                                                                                                                                         
    |* 21 |       HASH JOIN                         |                                |  6691 |   248K|       |  2489   (1)| 00:00:30 |                                                                                                                                                                         
    |* 22 |        TABLE ACCESS BY INDEX ROWID      | EVENTS                         |  1937 | 56173 |       |  2401   (1)| 00:00:29 |                                                                                                                                                                         
    |  23 |         BITMAP CONVERSION TO ROWIDS     |                                |       |       |       |            |          |                                                                                                                                                                         
    |  24 |          BITMAP AND                     |                                |       |       |       |            |          |                                                                                                                                                                         
    |  25 |           BITMAP OR                     |                                |       |       |       |            |          |                                                                                                                                                                         
    |  26 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 27 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  28 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 29 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  30 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 31 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  32 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 33 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  34 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 35 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  36 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 37 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  38 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 39 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  40 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 41 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  42 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 43 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  44 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 45 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  46 |            BITMAP CONVERSION FROM ROWIDS|                                |       |       |       |            |          |                                                                                                                                                                         
    |* 47 |             INDEX RANGE SCAN            | COUNTRY_DISPLAY_INDEX          | 30402 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |  48 |           BITMAP CONVERSION FROM ROWIDS |                                |       |       |       |            |          |                                                                                                                                                                         
    |* 49 |            INDEX RANGE SCAN             | EVENT_CODE_INDEX               | 30402 |       |       |    79   (0)| 00:00:01 |                                                                                                                                                                         
    |  50 |           BITMAP CONVERSION FROM ROWIDS |                                |       |       |       |            |          |                                                                                                                                                                         
    |* 51 |            INDEX RANGE SCAN             | IS_SCALL_INDEX                 | 30402 |       |       |   100   (1)| 00:00:02 |                                                                                                                                                                         
    |* 52 |        TABLE ACCESS FULL                | EVENT_KEYWORD_MAPPING          | 88609 |   778K|       |    87   (4)| 00:00:02 |                                                                                                                                                                         
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                        
       2 - filter(ROWNUM<=41)                                                                                                                                                                                                                                                                                  
       4 - filter(ROWNUM<=41)                                                                                                                                                                                                                                                                                  
      12 - access("EVENT_GMT_DATE">=TO_DATE(' 2011-12-27 05:14:00', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_GMT_DATE"<=TO_DATE('                                                                                                                                                                                  
                  2012-03-27 10:28:44', 'syyyy-mm-dd hh24:mi:ss'))                                                                                                                                                                                                                                             
           filter("EVENT_GMT_DATE"<=TO_DATE(' 2012-03-27 10:28:44', 'syyyy-mm-dd hh24:mi:ss') AND "EVENT_GMT_DATE">=TO_DATE('                                                                                                                                                                                  
                  2011-12-27 05:14:00', 'syyyy-mm-dd hh24:mi:ss'))                                                                                                                                                                                                                                             
      14 - access("EVENT_CODE"='ICC')                                                                                                                                                                                                                                                                          
      16 - access("FX_EVENT"='N')                                                                                                                                                                                                                                                                              
      18 - access("IS_GTINDEX"='Y')                                                                                                                                                                                                                                                                            
      21 - access("THIS_"."EVENT_ID"="EKP"."EVENT_ID")                                                                                                                                                                                                                                                         
      22 - filter(LNNVL("EVENT_CODE"='ICC') OR LNNVL("IS_GTINDEX"='Y') OR LNNVL("FX_EVENT"='N') OR                                                                                                                                                                                                             
                  LNNVL("EVENT_GMT_DATE">=TO_DATE(' 2011-12-27 05:14:00', 'syyyy-mm-dd hh24:mi:ss')) OR LNNVL("EVENT_GMT_DATE"<=TO_DATE('                                                                                                                                                                      
                  2012-03-27 10:28:44', 'syyyy-mm-dd hh24:mi:ss')))                                                                                                                                                                                                                                            
      27 - access("COUNTRY_DISPLAY"='AU')                                                                                                                                                                                                                                                                      
      29 - access("COUNTRY_DISPLAY"='BE')                                                                                                                                                                                                                                                                      
      31 - access("COUNTRY_DISPLAY"='CA')                                                                                                                                                                                                                                                                      
      33 - access("COUNTRY_DISPLAY"='CH')                                                                                                                                                                                                                                                                      
      35 - access("COUNTRY_DISPLAY"='DE')                                                                                                                                                                                                                                                                      
      37 - access("COUNTRY_DISPLAY"='EU')                                                                                                                                                                                                                                                                      
      39 - access("COUNTRY_DISPLAY"='FR')                                                                                                                                                                                                                                                                      
      41 - access("COUNTRY_DISPLAY"='IT')                                                                                                                                                                                                                                                                      
      43 - access("COUNTRY_DISPLAY"='JP')                                                                                                                                                                                                                                                                      
      45 - access("COUNTRY_DISPLAY"='UK')                                                                                                                                                                                                                                                                      
      47 - access("COUNTRY_DISPLAY"='US')                                                                                                                                                                                                                                                                      
      49 - access("EVENT_CODE"='IEP')                                                                                                                                                                                                                                                                          
      51 - access("IS_SCALL"='Y')                                                                                                                                                                                                                                                                              
      52 - filter("EKP"."KEYWORD_ID"=24 OR "EKP"."KEYWORD_ID"=401 OR "EKP"."KEYWORD_ID"=1090 OR "EKP"."KEYWORD_ID"=1643 OR                                                                                                                                                                                     
                  "EKP"."KEYWORD_ID"=2278 OR "EKP"."KEYWORD_ID"=2422)                                                                                                                                                                                                                                           When the above query is executed its taking around 10 seconds to return the data.
    I am using- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
    I need help in bringing down the query execution time.
    Thanks,
    Girish G

    A few questions:
    1. Are any indexes available on the Event_KeyWord_Mapping table?
    2. What does '1.4 L records' mean? Not familiar with 'L'.
    3. Are the statistics up to date for the tables and indexes involved?
    4. Are EVENT_ID and KEYWORD_ID the only columns accessed from the Event_KeyWord_Mapping table?
    Assuming the above then DarkStargate's suggestion is on point.
    But you should add the KEYWORD_ID column to the index as well since that is what the index records are filtered on.
    AND  ekp.keyword_id IN (
                            1643,2278,24,1090,2422,401 )Be sure that index statistics are collected; they will provide Oracle with data about the distribution of KEYWORD_ID values.
    This will allow Oracle to get the required information from the index without accessing the Event_KeyWord_Mapping table itself.

  • Need help in query to have all items in sap with PO data on order, date

    Hello Everyone,
    I need some help in writing a query to show all items in sap db to have itemcode, itemname, onhand, sellable(onhand-committed), on order, and the delivery date when that time should be received.  I need to know what items are regular items, which ones are master and components.  For the master I need to have the deliver date of the PO for the component.
    I have written this.
    SELECT DISTINCT TOP (100) PERCENT T1.ItemCode, SUM(T1.Sellable) AS Sellable, T1.OnOrder, MAX(T1.Docduedate) AS DeliveryDate, T1.WhsCode
    FROM         (SELECT     ItemCode, Sellable, OnOrder, '1/1/1900' AS Docduedate, WhsCode
                           FROM          dbo.V_RAZ_StoreInv
                           UNION ALL
                           SELECT     TOP (100) PERCENT ItemCode, '0' AS Sellable, Quantity AS Onorder, DocDueDate, WhsCode
                           FROM         dbo.V_RAZ_OPENPOSDATA
                           ORDER BY ItemCode) AS T1 LEFT OUTER JOIN
                          dbo.V_RAZ_ItemInfo ON T1.ItemCode = dbo.V_RAZ_ItemInfo.ItemCode
    GROUP BY T1.ItemCode, T1.OnOrder, T1.WhsCode, dbo.V_RAZ_ItemInfo.OnHold
    HAVING      (dbo.V_RAZ_ItemInfo.OnHold = 'n')
    ORDER BY T1.ItemCode, T1.WhsCode
    and for the v_raz_openposdata I have the following query
    SELECT     dbo.OPOR.DocNum, dbo.OPOR.DocStatus, dbo.POR1.WhsCode, dbo.POR1.ItemCode, dbo.POR1.Dscription, dbo.POR1.Quantity, dbo.POR1.OpenQty,
                          dbo.POR1.LineStatus, dbo.OPOR.DocDueDate
    FROM         dbo.OPOR LEFT OUTER JOIN
                          dbo.POR1 ON dbo.OPOR.DocEntry = dbo.POR1.DocEntry
    WHERE     (dbo.OPOR.DocStatus = 'O')
    Any help is greatly appreciated. 
    Right now I do get the delivery date for regular items and components but the master sku for the component all of them have 1/1/1900. 
    Thank you

    Thank you for replying Gordon.  I did not remember I had asked this before.  I no longer have access to the other account. 
    What I need on the query is that I want  a list of items with the on order quantity and when we are expecting this order to be received.  The receiving date is based on the PO delivery date.  The trick here is that  I need to Master sku to show the delivery date of the component sku.  In my scenario all components have the same delivery date for the Master sku.  If there are mulitple delivery dates because each warehouse is getting them on a different date then I want to get the delivery date for that warehouse.
    Let me know if this is possible and if yes please guide towards a query for it.
    Thank you.

  • Need a SQL query(Pls Its urgent)

    Hi,
    I want a SQL query for the foll..
    Details r below..
    Table AFPFTRAN
    BU TRansactiondate Amt
    13202 10-04-05 10,000
    13203 11-05-05 20,000
    13202 20-04-05 5,000
    Table AFGENCOD
    BU Clerk Name Clerk Code
    13202 Amit TFBG
    13203 Anand TFMG
    I want a query to get data as below..
    Tr Date TFBG TFMG
    Apr 15,000 0
    May 0 20,000
    JUn 0 0
    Jul 0 0
    Aug
    Sep
    Aug
    Nov
    DEc
    Jan
    Feb
    Mar
    I want this to achieve using a single query...?How can I achive this?
    Pls give the sol...
    Adios...
    Prashanth Deshmukh

    Does it look like you need ?
    SQL> select * from t;
            BU TDATE           AMT
         13202 10.04.05      10000
         13203 11.05.05      20000
         13202 20.04.05       5000
    SQL> select * from t1;
            BU NAME  CODE
         13202 Amit  TFBG
         13203 Anand TFMG
    SQL> SELECT pivot_month.mname, tops.TFBG, tops.TFMG
      2  from
      3  (
      4  select to_char(t.tdate,'MM') month_no,
      5  sum(decode(t1.code,'TFBG',t.amt,0)) TFBG,
      6  sum(decode(t1.code,'TFMG',t.amt,0)) TFMG
      7  from t1, t
      8  where t.bu=t1.bu
      9  and to_char(t.tdate,'yyyy') = 2005
    10  GROUP BY t1.code, to_char(t.tdate,'MM')
    11  ) tops,
    12  (select rownum mn, to_char(to_date(rownum,'MM'),'MON') mname,
    13  case when rownum between 1 and 3 then rownum + 9
    14  else rownum - 3 end rn
    15  from dict where rownum < 13) pivot_month
    16  where pivot_month.mn = tops.month_no (+)
    17  order by pivot_month.rn
    18  /
    MNA       TFBG       TFMG
    APR      15000          0
    MAY          0      20000
    JUN
    JUL
    AUG
    SEP
    OCT
    NOV
    DEC
    JAN
    FEB
    MAR
    12 rows selected.Rgds.

  • Proxy to JDBC scenario need dynamic sql query for sender .

    Hi Experts,
    I am developing proxy to jdbc scenario. in this i need to pass dynamic sql query  whre we are passing classical method like below.
    while we are passing select stmt in constant and mapped with access field  and key field mapped with key field.
    MY requirement is like instead of passing select stmt in constant where i can generate dynamically and passed in one field and mapped with access field.

    Hi Ravinder,
    A simple UDF or use of graphical mapping functions in most cases should provide you everything you need to construct a dynamic SQL statement for your requirement.
    Regards,
    Ryan Crosby

  • Need help on query simplification...!!

    Hi All,
    I need help on below query simplification using idempotence rules.
    SELECT ENO FROM AGS WHERE RESP = "Analyst" AND NOT (PNO = "P2" OR DUR = 12) AND PNO != "P2" AND DUR = 12;
    Thanks.

    928351 wrote:
    Hi All,
    I need help on below query simplification using idempotence rules.
    SELECT ENO FROM AGS WHERE RESP = "Analyst" AND NOT (PNO = "P2" OR DUR = 12) AND PNO != "P2" AND DUR = 12;
    Thanks.How do we know what the correct result set is?
    Handle:     928351
    Status Level:     Newbie
    Registered:     Apr 17, 2012
    Total Posts:     4
    Total Questions:     3 (3 unresolved)
    ZERO for three! STRIKE 3 you are out!

  • Need help in query to display lot and serial numbers for a Wip Job Component

    Hi ALL,
    I have a requirement as below.
    I need to display lot and serial numbers for a Wip Job Component, i have a xml report in that for each wip job component i need to check whether it is a lot control item or serial control item based on that i need to display some data. so can you please help me to get the query to indentify the lot and serial number for a wip job component.
    Thanks

    Thank you for replying Gordon.  I did not remember I had asked this before.  I no longer have access to the other account. 
    What I need on the query is that I want  a list of items with the on order quantity and when we are expecting this order to be received.  The receiving date is based on the PO delivery date.  The trick here is that  I need to Master sku to show the delivery date of the component sku.  In my scenario all components have the same delivery date for the Master sku.  If there are mulitple delivery dates because each warehouse is getting them on a different date then I want to get the delivery date for that warehouse.
    Let me know if this is possible and if yes please guide towards a query for it.
    Thank you.

  • Need help regarding query

    dear all,
    i am working with JDBC and Access database. I have a table name FilingTable and it has 6 column: title, mdate, tdate, place, content and person. the UI has a jdbtable where it shows all the data from the database. there are six textfield where i can give value seach for perticular row consisting this value. the quirement is : I may give a parameter, two parameter and may be six parameter the search will show the rows containing those value or closely similar to those value. I need help from you.
    zakir

    Hello,
    Try SQL with the LIKE condition to perform your search and % as wildcards.
    LIKE will however not find similar matches but only exact matches.
    Hope this helps
    Niklas

  • Need help wrt query

    Hi ,
    I have table A with below data :
    Name Sal
    Ram

    That's because it's over here:
    Need help wrt query

  • Help needed for SQL query

    hello ,
    I am a beginner in terms of writing sql queries. I hope some body can help me out.
    I have two tables
    mysql> desc user_group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | userAccountId | char(8) | | PRI | | |
    | groupId | char(8) | | PRI | | |
    ---------------------------------------------------+
    2 rows in set (0.00 sec)
    mysql> desc group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | id | char(8) | | PRI | | |
    | name | char(50) | YES | | NULL | |
    | email | char(100) | YES | | NULL | |
    | description | char(254) | YES | | NULL | |
    | parentId | char(8) | YES | | NULL | |
    | creatorId | char(8) | YES | | NULL | |
    | createDate | char(20) | YES | | NULL | |
    | updateDate | char(20) | YES | | NULL | |
    | updatorId | char(8) | YES | | NULL | |
    ---------------------------------------------------+
    9 rows in set (0.00 sec)
    what I want is list of all groups with id,name and #of members(which is the # of rows in the user_group_t for any given id). Importantly I need the groups with 0 members also to be listed. In short my output should contain exactly the same number of rows as in group_t table with an additional column indicating # of members for that group.
    Any help would be greatly appreciated.
    Thanks in Advance.
    -Vasanth

    Thanks Donald,
    Actually I figured it out, with the following query:
    select id,name,sum(if(groupid is not null,1,0)) as members from group_t left join user_group_t on id=groupid group by id;
    I tried your solution, but mysql says there is an error at '+' . Anyway I modified your solution to the one below and it worked.
    select a.id, a.name, count(b.groupid) from group_t a left join user_group_t b on a.id=b.groupid group by a.id, a.name;
    I tried that before but then I used Count(*) instead of count on groupid. Your solution is elagant and I will go with yours.
    Thanks again.
    Vasanth

Maybe you are looking for