Need to do Query Modifications

Hi
I am doing one report daywise production in that i am getting different values in below cases.
1. if i comment transaction date in group by getting quantity is differ.
2. when i commented or uncommented there is no diff. in quantity
--and bd.department_code<>'OSP'
3. if i use and bd.department_code='OSP' only this
i am getting some quantity..
select sum(a.Quantity_LLST/1000)--,to_char(a.transaction_date,'DD')
from
(select nvl((mmt.primary_quantity),0) Quantity_LLST
, trunc(mmt.transaction_date) transaction_date
from mtl_material_transactions mmt
, mtl_system_items_b msi
, wip_discrete_jobs wd
, wip_operations wo
, bom_departments bd
where 1=1
and mmt.organization_id=nvl(:P_ORG_ID,mmt.organization_id)
and mmt.transaction_type_id=44
and msi.inventory_item_id=wd.primary_item_id
and msi.organization_id=wd.organization_id
and wd.wip_entity_id=wo.wip_entity_id
and wd.organization_id=wo.organization_id
and wo.department_id=bd.department_id
and wo.organization_id=bd.organization_id
--and bd.department_code!='OSP'
and msi.segment1 like 'FG%LL%'
and mmt.inventory_item_id=msi.inventory_item_id
and mmt.organization_id=msi.organization_id
and trunc(mmt.transaction_date) between nvl(:P_FROM_DATE, trunc(mmt.transaction_date)) and nvl(:P_TO_DATE, trunc(mmt.transaction_date))
group by mmt.primary_quantity,trunc(mmt.transaction_date) )a
--group by to_char(a.transaction_date,'DD')                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

You really didn't say what you want. If you get different results when you remove different parts of your original query, it is not unusual.
What do you want in the first place? Your subject says you need to modify the query, what is the modification you want us to suggest when you have already commented out many parts of your code.
Cheers
Sarma.

Similar Messages

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

  • 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

  • I need a select query

    I have a dataset like below in two columns ( col1,col2 in table Mytable)
    A | ab
    A | cd
    A | ef
    B | xl
    B | ik
    E | 23
    E | op
    C | tk
    I need a select query which will return first set of every group which I ask for .
    For example, if I ask for data for A , B , the select query will return records
    A | ab
    B | xl
    For example, if I ask for data for B ,E the select query will return records..
    B | xl
    E | 23
    For example, if I ask for data for C the select query will return records..
    C | tk
    How do I write my select query ?

    Something like this ?
    SCOTT@orcl> create table test(col1 varchar2(1),col2 varchar2(2));
    Table created.
    SCOTT@orcl> insert into test values('A','ab');
    1 row created.
    SCOTT@orcl> insert into test values('A','cd');
    1 row created.
    SCOTT@orcl> insert into test values('A','ef');
    1 row created.
    SCOTT@orcl> insert into test values('B','xl');
    1 row created.
    SCOTT@orcl> insert into test values('B','ik');
    1 row created.
    SCOTT@orcl> insert into test values('E','23');
    1 row created.
    SCOTT@orcl> insert into test values('E','op');
    1 row created.
    SCOTT@orcl> insert into test values('C','tk');
    1 row created.
    SCOTT@orcl> commit;
    Commit complete.
    SCOTT@orcl>
    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  select * from (
      2  select decode(lag(col1) over (order by col1,rownum),null,col1
      3  ,col1,null
      4  ,col1) col1
      5  ,col2
      6  from test) aaa
      7* where aaa.col1='A'
    SCOTT@orcl> /
    C CO
    A abHTH
    Girish Sharma

  • 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 tcode for Query analyzer

    hi i want to test query in query analyzer befor using in programe.
    i need tcode for query analyzer.
    thanks in advanced.

    hi,,
    SE30 - gives you a run time analysis and points out the issues more at design time.
    ST05 - Is the most useful if you want to track time taken for execution of each of the sections.
    SM50 - Will give you a work process overview, not sure at a program level how can it help you.
    Some times you will have to use a combination of SE30 and ST05.
    I would like to use St05 personally.
    rgds
    anver
    if hlped mark points

  • 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 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.

  • I need that this query return only one value

    Hi, please. I need your help. I have this query:
    SELECT c.charvalue "Comentario", max(pi.id) as "id" --into :gcpe_last_comment
    FROM twflprocessinstances pi, twfliprocessparameters c
    WHERE pi.id = c.iprocess_id
    AND c.param_id = 1002286
    AND c.charvalue IS NOT NULL
    AND pi.processdef_id = 1600
    AND to_number(pi.id) <> 3817940
    AND to_number(pi.seeparameter1) =80137377
    group by c.charvalue
    having max(pi.id)
    This query return 3 rows, but I need that this query return only one row. The row that this query should return is the row before at the max id. Thanks

    Mmmm...I don't get it.
    You might need to post some sample data and expected results.

  • WHEN-TREE-NODE-SELECTED need 2 Execute-Query on Master-Detail data block

    I optimize tree using this link
    http://andreas.weiden.orcl.over-blog.de/article-29307730.html_+
    For huge amount of data (Accountings)
    All i need for now is
    WHEN-TREE-NODE-SELECTED need 2 Execute-Query on the data block
    DECLARE
    htree ITEM;
    node_value VARCHAR2(100);
    BEGIN
    IF :SYSTEM.TRIGGER_NODE_SELECTED = 'TRUE' THEN
    -- Find the tree itself.
    htree := FIND_ITEM ('BL_TREE.IT_TREE');
    node_value := FTREE.GET_TREE_NODE_PROPERTY( htree, :SYSTEM.TRIGGER_NODE ,  ftree.node_value  );
       GO_BLOCK ('GL_ACCOUNTS');
       set_block_property('GL_ACCOUNTS', DEFAULT_WHERE , 'ACCOUNT_ID ='|| node_value  );
    EXECUTE_QUERY;
    END IF;
    END;The above code is working fine 4 the detail block which is *'GL_ACCOUNTS'*
    when i substitute is Master block which is 'GL_ACCOUNTS_TYPES' it doesn't display all data
    Help is Appriciated pls.
    Regards,
    Abdetu...

    Hello
    In WHEN-TREE-NODE-SELECTED i modified the following code :_
    DECLARE
            htree ITEM;
           node_value VARCHAR2(100);
           parent_node FTREE.NODE;
    BEGIN
      IF :SYSTEM.TRIGGER_NODE_SELECTED = 'TRUE' THEN
      -- Find the tree itself.
      htree := FIND_ITEM ('BL_TREE.IT_TREE');
      -- Get the parent of the node clicked on. 
                  parent_node := FTREE.GET_TREE_NODE_PARENT ( htree, :SYSTEM.TRIGGER_NODE );
           GO_BLOCK('GL_TYPES');
                set_block_property('GL_TYPES', DEFAULT_WHERE , 'TYPE_ID ='|| parent_node  );
                  EXECUTE_QUERY;
      -- Get the detail of the parent node
          node_value := FTREE.GET_TREE_NODE_PROPERTY( htree, :SYSTEM.TRIGGER_NODE ,  ftree.node_value  );
               GO_BLOCK('GL_ACCOUNTS');
               set_block_property('GL_ACCOUNTS', DEFAULT_WHERE , 'ACCOUNT_ID ='|| node_value  );     
                   EXECUTE_QUERY;
          END IF;
    END;
    FRM-40350 : Query caused no records to be retrieved but i have records in the data base ...!
    Well, Do u think that's because in ur package i retrieve only the detail block ?
    Regards,
    Abdetu...

  • Need a FMS Query on Sales Order!!!!

    Dear Experts,
    I need a FMS query on SO with Following Conditions...
    **Current Stock(UDF @Raw Level)
    1.If InStock(as selected warehouse Quantity)>=Ordered Quantity Then Current stock Field should be taken Ordered Quantity.
    2.If InStock< Ordered quantity Then Current stock should be taken InStock Quantity
    Please provide me same...
    Thanks in advance...

    Hi Param,
                   Assign the following FMS to the row level UDF 'Current Stock'.
    Declare @a varchar(50)
    declare @b VARCHAR(50)
    declare @e varchar(50)
    declare @c integer
    declare @d integer
    set @b = (select $[RDR1.ItemCode])
    set @e = (select $[RDR1.WhsCode])
    SET @c = (select onhand from OITW where ItemCode = @b AND WhsCode = @e)
    set @d = (select OnOrder from OITW where ItemCode = @b AND WhsCode = @e)
    IF @c>=@d
    Begin
    set @a=@d
    select @a
    End
    ELSE IF @c<@d
    BEGIN
    set @a=@c
    select @a
    End
    Regards
    Sattanatha Raja

  • Small modification needed in sql query.

    Hi OTN,
    I have Below Query in which i'am fetching the Data from Target Aggregation Table.
    select
    TARGET_EMPLOYEE.FIRST_NAME||' ' ||TARGET_EMPLOYEE.LAST_NAME as Requestername,
    TARGET_EMPLOYEE.GE_ID as requesterGEID,
    TARGET_ATTENDEE.FIRST_NAME||' ' ||TARGET_ATTENDEE.LAST_NAME as AttendeeName,
    TARGET_ATTENDEE.ATTENDEE_TYPE_FLAG as Attendeetyflg,
    TARGET_ATTENDEE.US_GO_ATTENDEE_FLAG as usgoflg,
    TARGET_ATTENDEE.COMP_GOVT_AGENCY_DEPT as Atcomp,
    TARGET_ATTENDEE.COUNTRY as atcountry,
    TARGET_AGGREGATION_ATTENDEE.REQUEST_TYPE as requesttype,
    TARGET_PA_REQUEST.PA_REQUEST_ID as parequest,
    TARGET_PA_REQUEST.EVENT_DATE as eventdate,
    TARGET_PA_REQUEST.EVENT_DESCRIPTION as eventdesc,
    TARGET_PA_REQUEST.CREATED_DATE as requestdate,
    TARGET_PA_REQUEST.STATUS as status,
    TARGET_AGGREGATION_ATTENDEE.status,
    TARGET_AGGREGATION_ATTENDEE.be_aggregation_approved_amount as approved_amount,
    TARGET_AGGREGATION_ATTENDEE.level_id,
    TARGET_AGGREGATION_ATTENDEE.be_aggregation_pend_amount as req_amount
    from TARGET_ATTENDEE,
    TARGET_EMPLOYEE,
    TARGET_PA_REQUEST,
    TARGET_AGGREGATION_ATTENDEE
    where TARGET_ATTENDEE.ATTENDEE_ID=TARGET_AGGREGATION_ATTENDEE.ATTENDEE_ID
    and TARGET_EMPLOYEE.GE_ID=TARGET_AGGREGATION_ATTENDEE.REQUESTOR_ID
    and TARGET_AGGREGATION_ATTENDEE.PA_REQUEST_ID=TARGET_PA_REQUEST.PA_REQUEST_ID
    and to_char(TARGET_AGGREGATION_ATTENDEE.CREATED_DATE,'YYYY')=to_char(sysdate,'YYYY')
    and TARGET_AGGREGATION_ATTENDEE.pa_request_id='NAM1421';
    for fetching particular request id: NAM1421
    i'am getting output:
    REQUESTERNAME     REQUESTERGEID     ATTENDEENAME     ATTENDEETYFLG     USGOFLG     ATCOMP     ATCOUNTRY     REQUESTTYPE     PAREQUEST     EVENTDATE     EVENTDESC     REQUESTDATE     STATUS     STATUS_1     APPROVED_AMOUNT     LEVEL_ID     REQ_AMOUNT
    Danny Leung     1000650742     Mano hariram     Y     Y     BSNL     India     BE     NAM1421     13-AUG-12     fdg     13-AUG-12     APD               15     3
    Danny Leung     1000650742     Mano hariram     Y     Y     BSNL     India     BE     NAM1421     13-AUG-12     fdg     13-AUG-12     APD     Approved     3     70     0
    Danny Leung     1000650742     Mano hariram     Y     Y     BSNL     India     BE     NAM1421     13-AUG-12     fdg     13-AUG-12     APD               20     3
    But i need output like :
    Requested Amount, Approved Amount, Approved status in a single row.
    getting Requested Amount from TARGET AGGREGATION TABLE
    LOGIC: where Level_id should minimum that Levelid we have to get into Requested Amount.
    for Getting Approved Amount: where the status should be approved that corresponding amount should be in Approved Amount column.
    Thanks

    hi Matthew,
    I need output of above query like:
    in the Requested Amount Column from Target Aggregation Table should give (corresponding value of minimum Level id).
    In the Approved Amount Column from Target Aggregation Table should Give (Corresponding value of Approved status).
    Please suggest me how to achieve it.
    Table Data of Target Aggregation Table:
    PA_REQUEST_ID     STATUS     APPROVED_AMOUNT     LEVEL_ID     REQ_AMOUNT
    APAC1031     CAN          0     0.61336
    APAC1031     CAN          0     8.17212
    APAC1031     CAN          30     0
    APAC1031     CAN          30     0     
    APAC3873               0     
    APAC3873               80     
    APAC3873               0     
    APAC3873               80     
    APAC3873               30     
    APAC3873               70     
    APAC3873               30     
    APAC3873     Approved          80     
    APAC3873               60          
    APAC3997     Approved     0.08     80     0
    APAC3997     Approved          80     
    APAC3997     Approved          80     
    APAC3997               30     
    APAC3997               30     0.08
    APAC3997               30     
    APAC3997               0     
    APAC3997               0     0.08
    APAC3997               0     
    APAC3997               60     
    APAC3997               60     0.08
    APAC3997               60     
    APAC3998               0     
    APAC3998               30     
    APAC3998               0     
    APAC3998               0     
    APAC3998               30     
    APAC3998               30     
    APAC4001               0     
    APAC4004               30     
    APAC4004               30     
    APAC4004               0     
    APAC4004               0     
    APAC4004               80     
    APAC4004               0     
    APAC4004               80     
    APAC4004               0     
    APAC4004               60     
    APAC4006               30     
    APAC4006               30     
    APAC4006               0     
    APAC4006               0     
    APAC4007               0     
    APAC4007               0     0.08
    APAC4008               30     0.06
    APAC4008     Approved     0.06     80     0
    APAC4008               60     0.06
    APAC4008               0     0.06
    APAC4009               0     10
    APAC4009               0     10
    APAC4010               0     
    APAC4010               60     
    APAC4010               30     
    APAC4010     Approved          80     
    APAC4011               30     
    APAC4011               30     0.68
    APAC4011               0     
    APAC4011               0     0.68
    APAC4013               30     
    APAC4013               30     
    APAC4013               0     
    APAC4013               30     
    APAC4013               0     
    APAC4013               0     
    APAC4014               30     
    APAC4014               30     0.9
    APAC4014               0     
    APAC4014               0     0.9
    APAC4016               0     
    APAC4016               0     
    APAC4016               30     
    APAC4016               30     
    APAC4017     CAN          30     
    APAC4017     CAN          30     
    APAC4017     CAN          60     
    APAC4017     CAN          60     
    APAC4017     CAN          60     
    APAC4017     CAN          70     
    APAC4017     CAN          70     
    APAC4017     CAN          70     
    APAC4017     CAN          80     
    APAC4017     CAN          80     
    APAC4017     CAN          80     
    APAC4017     CAN          30     
    APAC4017     CAN          0     
    APAC4017     CAN          0     
    APAC4017     CAN          0     
    APAC4019               60     0.08
    APAC4019     Approved          80     
    APAC4019     Approved     0.08     80     0
    APAC4019               30     
    APAC4019               60     
    APAC4019               30     0.08
    APAC4019               0     0.08
    APAC4019               0     
    APAC4023     Rejected          0     0.12
    APAC4025     CAN          80     
    APAC4025     CAN          80     
    APAC4025     CAN          0     
    APAC4025     CAN          0     
    APAC4025     CAN          0     
    APAC4025     CAN          30     
    APAC4025     CAN          30     
    APAC4025     CAN          30     
    APAC4025     CAN          60     
    APAC4025     CAN          60     
    APAC4025     CAN          60     
    APAC4025     CAN          70     
    APAC4025     CAN          70     
    APAC4025     CAN          70     
    APAC4025     CAN          80     
    APAC4027               80     
    APAC4027               80     
    APAC4027               80     
    APAC4027               70     
    APAC4027               70     
    APAC4027               70     
    APAC4027               60     
    APAC4027               60     
    APAC4027               60     
    APAC4027               30     
    APAC4027               30     
    APAC4027               30     
    APAC4027               0     
    APAC4027               0     
    APAC4027               0     
    APAC4028               60     
    APAC4028               0     
    APAC4028               0     
    APAC4028               70     
    APAC4028               70     
    APAC4028               70     
    APAC4028               60     
    APAC4028               60     
    APAC4028               30     
    APAC4028               30     
    APAC4028               30     
    APAC4028               0     
    APAC4029     Rejected          0

  • 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

  • Need help with query that can look data back please help.

    hi guys i have a table like such
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )and i have a data like such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
    fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
    so im trying to write a query that basically does the following.
    im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
    so the expected outcome should be $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400keep in mind that im not given a year just a period.
    any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
    finally broke down and put together this post
    Edited by: mlov83 on Sep 14, 2011 8:48 PM

    Frank
    wondering if you can help me modify this sql statement that you provided me with .
    table values have been modified a bit.
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
    the current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    Miguel

  • Urgent help needed on 1 query

    Hello All,
    I have just started working in PL/SQL,
    I need some help on 1 urgent issue.
    i have a table lets say which has structure and values like below:
    ID Data Key Data Value
    1 Firstname X
    2 Lastname Y
    3 Middlename Z
    but my query shd return me data having firstname ,middlenale and last name as column names and lvalues like lsited below:
    Firstname Middlename Lastname
    X Y Z
    Please help and i really appreciate for your time and help!!!!!!!!!!
    Thanks and Regards

    Urgent? I don't think so.
    However, as others have mentioned, what groups the items together so that the relationship is known between them?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as id, 'Firstname' as data_key, 'Fred' as data_val from dual union all
      2             select 2, 'Surname', 'Bloggs' from dual union all
      3             select 3, 'Middlename', 'J' from dual union all
      4             select 4, 'Firstname', 'John' from dual union all
      5             select 5, 'Surname', 'Doe' from dual union all
      6             select 6, 'Middlename', 'D' from dual)
      7  --
      8  select id-decode(data_key,'Surname',1,'Middlename',2,0) as id
      9        ,max(decode(data_key,'Firstname',data_val)) as Firstname
    10        ,max(decode(data_key,'Middlename',data_val)) as Middlename
    11        ,max(decode(data_key,'Surname',data_val)) as Surname
    12  from t
    13* group by id-decode(data_key,'Surname',1,'Middlename',2,0)
    SQL> /
            ID FIRSTN MIDDLE SURNAM
             1 Fred   J      Bloggs
             4 John   D      Doe
    SQL>This example assumes that a Firstname, Surname and Middlename appear in that order with sequential ID's, such that the ID for Surname is always 1 more than the ID for it's associated Forename and the ID for Middlename is always 2 more than the associated Forename.

Maybe you are looking for