How to write this query.. Please Help

Hello Guys,
I have a table that contains all possible leave types, it is a look up table. Table name is Att_Leave_Types and data in the table is:
Leavetype_ID Leavetype_Desc
1 Annaul
2 Sick
3 Casual
4 Long
5 Maternity
Now, another table Att_Emp_Leaves Contains leaves of an employee
Columns and values are
Emp_ID leave_date levetype_id
14210 28-AUG-06 2
14210 30-AUG-06 3
14210 12-JUL-06 1
14210 13-JUL-06 1
14210 14-JUL-06 1
6902 27-AUG-06 2
6902 30-AUG-06 3
Now i want to get the following result from the query:
Group by month and year
list all leavetypes and leaves employee have availved, if no leavetype availved then the result must show 0 for the leavetype. calculate leaves for a month based on leavetype ID.
This result will help you clear what i result i want by my query.
MON_YYYY employee_id leavetype_id number_of_leaves
JUL-2006 14210 1 3
JUL-2006 14210 2 0
JUL-2006 14210 3 0
JUL-2006 14210 4 0
JU:-2006 14210 5 0
AUG-2006 14210 1 0
AUG-2006 14210 2 1
AUG-2006 14210 3 1
AUG-2006 14210 4 0
AUG-2006 14210 5 0
AUG-2006 6902 1 0
AUG-2006 6902 2 1
AUG-2006 6902 3 1
AUG-2006 6902 4 0
AUG-2006 6902 5 0
Please guide me and help me, its very urgent.
I will be thankful to you.
Regards,
Imran Baig

Here we are:
DROP TABLE Att_Leave_Types;
CREATE TABLE Att_Leave_Types
           Leavetype_ID NUMBER
          ,Leavetype_Desc VARCHAR2(30)
INSERT INTO Att_Leave_Types VALUES(1, 'Annual');
INSERT INTO Att_Leave_Types VALUES(2, 'Sick');
INSERT INTO Att_Leave_Types VALUES(3, 'Casual');
INSERT INTO Att_Leave_Types VALUES(4, 'Long');
INSERT INTO Att_Leave_Types VALUES(5, 'Maternity');
DROP TABLE Att_Emp_Leaves;
CREATE TABLE Att_Emp_Leaves
           Emp_ID NUMBER
          ,leave_date DATE
          ,leavetype_id NUMBER
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('01-JUL-2006', 'DD-MON-YYYY'), 1);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('10-JUL-2006', 'DD-MON-YYYY'), 1);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('15-JUL-2006', 'DD-MON-YYYY'), 1);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('15-AUG-2006', 'DD-MON-YYYY'), 2);
INSERT INTO Att_Emp_Leaves VALUES (14210, TO_DATE('25-AUG-2006', 'DD-MON-YYYY'), 3);
INSERT INTO Att_Emp_Leaves VALUES (6902, TO_DATE('15-AUG-2006', 'DD-MON-YYYY'), 2);
INSERT INTO Att_Emp_Leaves VALUES (6902, TO_DATE('25-AUG-2006', 'DD-MON-YYYY'), 3);
SELECT
          LP.*
          ,EL.Leave_date
COLUMN Emp_ID FOR 999999
COLUMN Leave_Month FOR A8
COLUMN Leavetype_ID FOR 999
COLUMN Leavetype_desc FOR A10
COLUMN Leave_Count FOR 999
SELECT
           LP.Emp_ID
          ,TO_CHAR(LP.Leave_Month, 'MON-YYYY') Leave_Month
          ,LP.Leavetype_ID
          ,LP.Leavetype_desc
          ,COUNT(EL.Emp_ID) Leave_Count
     FROM
          SELECT *
               FROM
                    SELECT
                               Emp_ID
                              ,ADD_MONTHS(Min_Leave_month, RN - 1) Leave_Month
                              ,Max_Leave_month
                         FROM
                              SELECT ROWNUM RN FROM
                                   USER_OBJECTS
                                   WHERE ROWNUM <= 100
                              SELECT
                                         Emp_ID
                                        ,TRUNC(MIN(Leave_date), 'MM') Min_Leave_month
                                        ,TRUNC(MAX(Leave_date), 'MM') Max_Leave_month
                                   FROM Att_Emp_Leaves
                                   GROUP BY Emp_ID
                         WHERE ADD_MONTHS(Min_Leave_month, RN - 1) <= Max_Leave_month
                    ,Att_Leave_Types
               -- ORDER BY Emp_ID, Leave_Month, Leavetype_ID
          ) LP -- Leave periods
          ,Att_Emp_Leaves EL -- Employee leaves
     WHERE EL.Emp_ID(+) = LP.Emp_ID
          AND EL.Leavetype_ID(+) = LP.Leavetype_ID
          AND EL.Leave_date(+) >= LP.Leave_Month
          AND EL.Leave_date(+) < ADD_MONTHS(LP.Leave_Month, 1)
     GROUP BY
           LP.Emp_ID
          ,LP.Leave_Month
          ,LP.Leavetype_ID
          ,LP.Leavetype_desc
     ORDER BY
           LP.Emp_ID
          ,LP.Leave_Month
          ,LP.Leavetype_ID
EMP_ID LEAVE_MO LEAVETYPE_ID LEAVETYPE_ LEAVE_COUNT
  6902 AUG-2006            1 Annual               0
  6902 AUG-2006            2 Sick                 1
  6902 AUG-2006            3 Casual               1
  6902 AUG-2006            4 Long                 0
  6902 AUG-2006            5 Maternity            0
14210 JUL-2006            1 Annual               3
14210 JUL-2006            2 Sick                 0
14210 JUL-2006            3 Casual               0
14210 JUL-2006            4 Long                 0
14210 JUL-2006            5 Maternity            0
14210 AUG-2006            1 Annual               0
14210 AUG-2006            2 Sick                 1
14210 AUG-2006            3 Casual               1
14210 AUG-2006            4 Long                 0
14210 AUG-2006            5 Maternity            0
     BW

Similar Messages

  • I can't forcequit firefox and shutdown my computer, nor can I open up any other programs or applications. Does anyone know how to fix this? please help this poor soul.

    I can't forcequit firefox and shutdown my computer, nor can I open up any other programs or applications. Does anyone know how to fix this? please help this poor soul.

    You can force quit applications
    >Force quit
    if that does not work you can force quit a computer shut down by hold the power button for an extended period.

  • After upgrading my iPhone 5 to iOS 7 iTunes will not stay open once the app launches...does anyone know how to fix this? Please Help :)

    After upgrading my iPhone 5 to iOS 7 iTunes will not stay open once the app launches...does anyone know how to fix this? Please Help :)

    I have exactly the same problem. I too have tried everything that's been suggested, but still not working. Don't really what to do next? I have an iPhone 4S.

  • How to write this query to filter combination of few values

    Hi,
    I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
    columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
    HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
    I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
    OR
    if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
    How to write this query?
    Regards

    Hi,
    I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
    CHILD_ID
           3
           4? If so, here's one way to get them:
    WITH     all_vacc_ids     AS
         SELECT     c.child_id
         ,     c.vacc_id          AS child_vacc_id
         ,     v.vacc_id
         ,     COUNT ( CASE
                             WHEN  c.vacc_id = 'HEXA'
                       THEN  1
                         END
                    )       OVER ( PARTITION BY  c.child_id
                                       )    AS hexa_itself
         FROM          vacc   v
         LEFT OUTER JOIN     chimm  c     PARTITION BY (c.child_id)
                          ON     c.vacc_id     = v.vacc_id
         WHERE   v.vacc_desc       = 'HEXA'     -- See note below
    SELECT       child_id
    FROM       all_vacc_ids
    WHERE       child_vacc_id     IS NULL
      AND       vacc_id     != 'HEXA'
      AND       hexa_itself     = 0
    GROUP BY  child_id
    rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
    You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher).

  • How to write this query ?

    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno

    Hi,
    806540 wrote:
    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
    ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno
    If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
    You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
    Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
    If you really, really don't want to use analytic functions at all, you can do this:
    SELECT     *
    FROM     scott.emp
    WHERE     deptno     IN  (
                      SELECT       deptno
                      FROM       scott.emp
                      GROUP BY  deptno
                      HAVING       AVG (sal) =  (
                                                       SELECT    MAX (AVG (sal))
                                               FROM          scott.emp
                                               GROUP BY  deptno
    ;

  • Can Any one tell me. System considering the Sales District also in Delivery Split which is not in standard. How to resolve this. Please help me

       Hi
    Can Any one tell me. System considering the Sales District also in Delivery Split which is not in standard. How to resolve this. Please help me

    Dear Srikanth,
    I am not sure, if my answer will satisfy you, but anyway I will try:
    Field Sales District is technically called BZIRK. In delivery structure is this field located in header (table LIKP), what cause split, if origin document (Sales Order) has different Sales District in some positions. This is standard program behavior. Basically it shouldn't happen, as value is taken from customer master (Sold-to Party) and copied to header and items of sales document. But user can manually changer for particular items.
    Well, to solve situation you have few ways:
    1. Do not allow users to change value on items - can be managed by organizational decision or by authorization concept.
    2. If there is a reason to have different Sales District in items, then it can be managed in in routines for copy control between sales and delivery documents (delete value of BZIRK for all items for instance). But then will be this information lost for further usage. It seems to me to invoice is value copied directly from sales order (field VBRP-BZIRK_AUFT) then it mustn't be a critical for analyses.
    3. Your situation also can happen if you wants to collect more sales documents to one delivery. In this case can be that Sales District is different for same customer in different sales order (even seems to be little bit strange). Then solution from point 2 can help as well, I believe.
    Best Regards
    Arnost

  • I'm not sure how to explain this but PLEASE HELP! ...

    okay so I'm not quite sure if anyone is going to understand what I'm talking about...
    But for some reason when someone adds me to skype (sends me a request) it says "Hi, White Asian!... so and so wants to add you.. blahblah etc." It says something other than my current user name, or my current display name, or my first and last name. I have know idea why it says this. I've had skype for a long time now and several years ago I believe that I changed my display name to "White Asian" as a joke. It hasn't been that for a long time now and I have no idea why it shows up like that when someone sends me a request on skype. I've tried changing every possible thing to do with a name in the profile/user settings to no avail. THe only time it shows up (that I'm aware of) is when someone adds me.
    So if you have any idea how I can fix this or why it's happening please let me know immediately!
    Its driving me mad because I don't know how to fix this!
    Thanks!
    Attachments:
    Untitled.png ‏11 KB

    Try this website. Yes its sprint but it might help you. http://support.sprint.com/support/article/Troubleshoot_issues_related_to_your_Sa msung_Galaxy_S_II_not_turning_on_completely/WTroubleshootingGuide_542_GKB51165-T rend?INTNAV=SU:DP:OV:TSIS:SamsungGalaxySIi-AsYouGo:TroubleshootIssuesRelatedToYo urSamsungG

  • How to make recursive query.Please help

    Dear Experts:
    I want to retrieve all employees located in a department in addition to all other employees located in the child's nodes of this department too.
    Problem Details:
    I have "Employees" table and "Departments" Table
    The structure of Dept Table is:
    ID   primary key
    parent_dept   foreign key(id)
    deptname  varchar2
    deptType varchar2
    The Employee table structure is
    ID primary key
    dept_id foreign key(Department.id)
    empName varchar2Sample data for departments
    ID : 1
    parent_dept : null
    deptname: General Manager office
    deptType : 'GM'
    ID :=2
    parent_dept : 1
    deptname: Information tech.
    deptType : 'DPT'
    ID :=3
    parent_dept : 2
    deptname: Software Development
    deptType : 'SECTION'Sample Data for employees
    ID : 101
    dept_id  :1
    empName  King
    ID : 102
    dept_id  :2
    empName  ALAN
    ID : 103
    dept_id  :2
    empName  SAM
    ID : 104
    dept_id  :3
    empName  JANEI want to create a query that accepts a parameter "p_department_id" and returns All employees on the following conditions
    1- In case the parameter value is null , then retrieve All Employees "king - alan- sam-jane"
    2- In Case the parameter value is 1 , then retrieve all the employees under department id =1 in addition to all the employees located under the children departments.
    in this case it will be "king - alan- sam-jane"
    3- In case parameter value is 2 , then return all the employees under department id =2 in addition to all the employees located under the children departments.
    In this case it will be " alan- sam-jane"
    4- In case parameter value is 3 , then return all the employees under department id =3 in addition to all the employees located under the children departments.
    in this case it will be only "JANE"
    In brief , If I pass any value to the parameter :p_department_id , I want to retrieve all employees located in this department in addition to other employees located in the child's nodes of this department id
    I use oracle database 11g release 2
    Please help me
    Thanks
    Edited by: ta**** on Apr 3, 2013 5:56 PM
    Edited by: ta**** on Apr 3, 2013 5:58 PM

    SQL> variable p_department_id number
    SQL> exec :p_department_id := null
    PL/SQL procedure successfully completed.
    SQL> with employees as (
      2                     select 101 id,1 dept_id,'King' empName from dual union all
      3                     select 102,2,'ALAN' from dual union all
      4                     select 103,2,'SAM' from dual union all
      5                     select 104,3,'JANE' from dual
      6                    ),
      7     departments as (
      8                     select 1 id,null parent_dept,'General Manager office' deptname,'GM' deptType from dual union all
      9                     select 2,1,'Information tech.','DPT' from dual union all
    10                     select 3,2,'Software Development','SECTION' from dual
    11                    )
    12  select  *
    13    from  employees
    14    where dept_id in (
    15                      select  id
    16                        from  departments
    17                        start with (
    18                                       (
    19                                            :p_department_id is null
    20                                        and
    21                                            parent_dept is null
    22                                       )
    23                                    or
    24                                       id = :p_department_id
    25                                   )
    26                        connect by parent_dept = prior id
    27                     )
    28  /
            ID    DEPT_ID EMPN
           101          1 King
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 1
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           101          1 King
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 2
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 3
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           104          3 JANE
    SQL> SY.

  • Please tell me anything wrong in this query please help me follwing query

    SELECT o100161.ORG_STRUCTURE_VERSION_ID as E100351,AVG(o100163.PLANNED) as E100360_AVG,AVG(o100163.ACTUAL) as E100180_AVG,( SUM(fx102) )-( SUM(fx103) ) as C_1,( SUM(fx105) )-( SUM(fx106) ) as C_2,( SUM(fx108) )-( SUM(fx109) ) as C_3
    FROM ( SELECT o100165.SEGMENT1 AS fx100, SUM(o100165.ACR) AS fx102, SUM(o100165.ADR) AS fx103, SUM(o100165.BDR) AS fx105, SUM(o100165.BCR) AS fx106, SUM(o100165.ECR) AS fx108, SUM(o100165.EDR) AS fx109 FROM ( SELECT
    nvl(src.user_je_source_name, '**************') SOURCE,
    nvl(cat.user_je_category_name, '**************') CATEGORY,
    jeh.name NAME,
    jel.code_combination_id CCID,
    jeh.DEFAULT_EFFECTIVE_DATE,
    jel.period_name PERIOD_NAME,
    jel.effective_date EFFECTIVE_DATE,
    jel.description DESCRIPTION,
    seq.name SEQUENCE_NAME,
    jeh.doc_sequence_value DOCUMENT_NUMBER,
    jel.accounted_dr,
    jel.accounted_cr,
    decode(jeh.actual_flag,'B',jel.accounted_dr,'E',0,'A',0)bdr,
    decode(jeh.actual_flag,'B',jel.accounted_Cr,'E',0,'A',0)bcr,
    decode(jeh.actual_flag,'B',0,'E',jel.accounted_Dr,'A',0)EDr,
    decode(jeh.actual_flag,'B',0,'E',jel.accounted_Cr,'A',0)ECr,
    decode(jeh.actual_flag,'B',0,'E',0,'A',jel.accounted_Dr)ADr,
    decode(jeh.actual_flag,'B',0,'E',0,'A',jel.accounted_Cr)ACr,
    jel.JE_LINE_NUM,
    cc.segment7 Project_COA_No,
    cc.description Segment_description,
    pa.segment1,
    jeh.actual_flag,
    PA.NAME PROJECT_NAME,
    cc.segment1||'.'||cc.segment2||'.'||cc.segment3||'.'||cc.segment4||'.'||cc.segment5 seg_desc
    FROM gl_je_lines jel,
    gl_code_combinations cc,
    gl_je_headers jeh,
    -- gl_je_batches jeb,
    gl_je_categories cat,
    gl_je_sources src,
    fnd_document_sequences seq,
    pa_projects_all pa,
    XXEPM_FINANCE_INTEGRATION XX
    WHERE
    ((nvl(accounted_dr,0) != 0 OR nvl(accounted_cr,0) != 0) OR
    (nvl(accounted_dr,0) = 0 AND nvl(accounted_cr,0) = 0 AND
    stat_amount is not NULL))
    AND jeh.je_header_id = jel.je_header_id
    AND src.je_source_name = jeh.je_source
    AND cat.je_category_name = jeh.je_category
    AND seq.doc_sequence_id(+) = jeh.doc_sequence_id
    AND jel.code_combination_id = cc.code_combination_id
    AND XX.EPM_PA_NO=PA.SEGMENT1
    AND XX.FINANCE_PA_COA_SEG=CC.SEGMENT7
    ORDER BY jeh.name, jel.je_line_num
    ) o100165 GROUP BY o100165.SEGMENT1) ,
    ( select * from PER_ORG_STRUCTURE_ELEMENTS_V
    ) o100161,
    ( SELECT PPA.CARRYING_OUT_ORGANIZATION_ID Organization, PPA.PROJECT_ID as "Project ID",ppa.segment1 as "Project No" ,PPA.NAME as "Project Name",
    nvl(trunc(((sysdate - PPA.SCHEDULED_START_DATE)/( PPA.scheduled_finish_date - PPA.SCHEDULED_START_DATE) *100 )),0) Planned,
    nvl(TRUNC(AVG(PPC.COMPLETED_PERCENTAGE)),0) Actual
    FROM PA_PROJECTS_ALL PPA , PA_PERCENT_COMPLETES PPC
    WHERE PPA.CARRYING_OUT_ORGANIZATION_ID IN (SELECT A.ORGANIZATION_ID_CHILD
    FROM PER_ORG_STRUCTURE_ELEMENTS_V A, PA_IMPLEMENTATIONS_ALL B
    WHERE A.ORG_STRUCTURE_VERSION_ID= B.ORG_STRUCTURE_VERSION_ID)
    AND PPA.TEMPLATE_FLAG='N'
    AND PPC.PROJECT_ID(+) = PPA.PROJECT_ID
    GROUP BY PPA.CARRYING_OUT_ORGANIZATION_ID,PPA.PROJECT_ID,ppa.segment1, PPA.NAME ,PPA.SCHEDULED_START_DATE,PPA.scheduled_finish_date
    ) o100163
    WHERE ( (o100163."Project No" = fx100)
    and (o100161.ORGANIZATION_ID_CHILD = o100163.ORGANIZATION))
    GROUP BY o100161.ORG_STRUCTURE_VERSION_ID;
    the second query is as follows
    SELECT o100163."Project Name" as E100386,( SUM(o100165.ACR) )-( SUM(o100165.ADR) ) as C_1,( SUM(o100165.BDR) )-( SUM(o100165.BCR) ) as C_2,( SUM(o100165.ECR) )-( SUM(o100165.EDR) ) as C_3
    FROM ( SELECT PPA.CARRYING_OUT_ORGANIZATION_ID Organization, PPA.PROJECT_ID as "Project ID",ppa.segment1 as "Project No" ,PPA.NAME as "Project Name",
    nvl(trunc(((sysdate - PPA.SCHEDULED_START_DATE)/( PPA.scheduled_finish_date - PPA.SCHEDULED_START_DATE) *100 )),0) Planned,
    nvl(TRUNC(AVG(PPC.COMPLETED_PERCENTAGE)),0) Actual
    FROM PA_PROJECTS_ALL PPA , PA_PERCENT_COMPLETES PPC
    WHERE PPA.CARRYING_OUT_ORGANIZATION_ID IN (SELECT A.ORGANIZATION_ID_CHILD
    FROM PER_ORG_STRUCTURE_ELEMENTS_V A, PA_IMPLEMENTATIONS_ALL B
    WHERE A.ORG_STRUCTURE_VERSION_ID= B.ORG_STRUCTURE_VERSION_ID)
    AND PPA.TEMPLATE_FLAG='N'
    AND PPC.PROJECT_ID(+) = PPA.PROJECT_ID
    GROUP BY PPA.CARRYING_OUT_ORGANIZATION_ID,PPA.PROJECT_ID,ppa.segment1, PPA.NAME ,PPA.SCHEDULED_START_DATE,PPA.scheduled_finish_date
    ) o100163,
    ( SELECT
    nvl(src.user_je_source_name, '**************') SOURCE,
    nvl(cat.user_je_category_name, '**************') CATEGORY,
    jeh.name NAME,
    jel.code_combination_id CCID,
    jeh.DEFAULT_EFFECTIVE_DATE,
    jel.period_name PERIOD_NAME,
    jel.effective_date EFFECTIVE_DATE,
    jel.description DESCRIPTION,
    seq.name SEQUENCE_NAME,
    jeh.doc_sequence_value DOCUMENT_NUMBER,
    jel.accounted_dr,
    jel.accounted_cr,
    decode(jeh.actual_flag,'B',jel.accounted_dr,'E',0,'A',0)bdr,
    decode(jeh.actual_flag,'B',jel.accounted_Cr,'E',0,'A',0)bcr,
    decode(jeh.actual_flag,'B',0,'E',jel.accounted_Dr,'A',0)EDr,
    decode(jeh.actual_flag,'B',0,'E',jel.accounted_Cr,'A',0)ECr,
    decode(jeh.actual_flag,'B',0,'E',0,'A',jel.accounted_Dr)ADr,
    decode(jeh.actual_flag,'B',0,'E',0,'A',jel.accounted_Cr)ACr,
    jel.JE_LINE_NUM,
    cc.segment7 Project_COA_No,
    cc.description Segment_description,
    pa.segment1,
    jeh.actual_flag,
    PA.NAME PROJECT_NAME,
    cc.segment1||'.'||cc.segment2||'.'||cc.segment3||'.'||cc.segment4||'.'||cc.segment5 seg_desc
    FROM gl_je_lines jel,
    gl_code_combinations cc,
    gl_je_headers jeh,
    -- gl_je_batches jeb,
    gl_je_categories cat,
    gl_je_sources src,
    fnd_document_sequences seq,
    pa_projects_all pa,
    XXEPM_FINANCE_INTEGRATION XX
    WHERE
    ((nvl(accounted_dr,0) != 0 OR nvl(accounted_cr,0) != 0) OR
    (nvl(accounted_dr,0) = 0 AND nvl(accounted_cr,0) = 0 AND
    stat_amount is not NULL))
    AND jeh.je_header_id = jel.je_header_id
    AND src.je_source_name = jeh.je_source
    AND cat.je_category_name = jeh.je_category
    AND seq.doc_sequence_id(+) = jeh.doc_sequence_id
    AND jel.code_combination_id = cc.code_combination_id
    AND XX.EPM_PA_NO=PA.SEGMENT1
    AND XX.FINANCE_PA_COA_SEG=CC.SEGMENT7
    ORDER BY jeh.name, jel.je_line_num
    ) o100165
    WHERE ( (o100163."Project No" = o100165.SEGMENT1))
    GROUP BY o100163."Project Name";

    > please tell me anything wrong in this query
    Umm, it's completely unreadable?
    Even formatted (with a little help from the wangz.net online SQL formatter, though it needed some manual editing) it's pretty hard to see what it's meant to be doing, due to all the nesting and cryptic naming. This is just the first one:
    SELECT o100161.org_structure_version_id AS e100351
         , AVG(o100163.planned) AS e100360_avg
         , AVG(o100163.actual) AS e100180_avg
         , SUM(fx102) - SUM(fx103) AS c_1
         , SUM(fx105) - SUM(fx106) AS c_2
         , SUM(fx108) - SUM(fx109) AS c_3
    FROM   ( SELECT o100165.segment1 AS fx100
                  , SUM(o100165.acr) AS fx102
                  , SUM(o100165.adr) AS fx103
                  , SUM(o100165.bdr) AS fx105
                  , SUM(o100165.bcr) AS fx106
                  , SUM(o100165.ecr) AS fx108
                  , SUM(o100165.edr) AS fx109
             FROM   GG( SELECT NVL(src.user_je_source_name,'**************') source
                           , NVL(cat.user_je_category_name,'**************') category
                           , jeh.NAME NAME
                           , jel.code_combination_id ccid
                           , jeh.default_effective_date
                           , jel.period_name period_name
                           , jel.effective_date effective_date
                           , jel.description description
                           , seq.NAME sequence_name
                           , jeh.doc_sequence_value document_number
                           , jel.accounted_dr
                           , jel.accounted_cr
                           , DECODE(jeh.actual_flag, 'B',jel.accounted_dr, 'E',0, 'A',0) bdr
                           , DECODE(jeh.actual_flag, 'B',jel.accounted_cr, 'E',0, 'A',0) bcr
                           , DECODE(jeh.actual_flag, 'B',0, 'E',jel.accounted_dr, 'A',0) edr
                           , DECODE(jeh.actual_flag, 'B',0, 'E',jel.accounted_cr, 'A',0) ecr
                           , DECODE(jeh.actual_flag, 'B',0, 'E',0, 'A',jel.accounted_dr) adr
                           , DECODE(jeh.actual_flag, 'B',0, 'E',0, 'A',jel.accounted_cr) acr
                           , jel.je_line_num
                           , cc.segment7 project_coa_no
                           , cc.description segment_description
                           , pa.segment1
                           , jeh.actual_flag
                           , pa.NAME project_name
                           , cc.segment1 ||'.' ||cc.segment2 ||'.' ||cc.segment3 ||'.'
                           ||cc.segment4 ||'.' ||cc.segment5 seg_desc
                      FROM   gl_je_lines jel
                           , gl_code_combinations cc
                           , gl_je_headers jeh
                           , gl_je_categories cat
                           , gl_je_sources src
                           , fnd_document_sequences seq
                           , pa_projects_all pa
                           , xxepm_finance_integration xx
                      WHERE  (    ( NVL(accounted_dr,0) != 0 OR NVL(accounted_cr,0) != 0 )
                              OR  (    NVL(accounted_dr,0) = 0
                                   AND NVL(accounted_cr,0) = 0
                                   AND stat_amount IS NOT NULL ) )
                      AND    jeh.je_header_id = jel.je_header_id
                      AND    src.je_source_name = jeh.je_source
                      AND    cat.je_category_name = jeh.je_category
                      AND    seq.doc_sequence_id (+)  = jeh.doc_sequence_id
                      AND    jel.code_combination_id = cc.code_combination_id
                      AND    xx.epm_pa_no = pa.segment1
                      AND    xx.finance_pa_coa_seg = cc.segment7
                      ORDER BY jeh.NAME, jel.je_line_num) o100165
              GROUP BY o100165.segment1)
         , ( SELECT *
             FROM   per_org_structure_elements_v) o100161
         , ( SELECT ppa.carrying_out_organization_id organization
                  , ppa.project_id AS "Project ID"
                  , ppa.segment1 AS "Project No"
                  , ppa.NAME AS "Project Name"
                  , NVL
                    ( TRUNC
                      ( ( (SYSDATE - ppa.scheduled_start_date) /
                          (ppa.scheduled_finish_date - ppa.scheduled_start_date) * 100)
                    , 0) planned
                  , NVL(TRUNC(AVG(ppc.completed_percentage)),0) actual
             FROM   pa_projects_all ppa
                  , pa_percent_completes ppc
             WHERE  ppa.carrying_out_organization_id IN
                    ( SELECT a.organization_id_child
                      FROM   per_org_structure_elements_v a
                           , pa_implementations_all b
                      WHERE  a.org_structure_version_id = b.org_structure_version_id )
             AND    ppa.template_flag = 'N'
             AND ppc.project_id (+)  = ppa.project_id
             GROUP BY
                    ppa.carrying_out_organization_id
                  , ppa.project_id
                  , ppa.segment1
                  , ppa.NAME
                  , ppa.scheduled_start_date
                  , ppa.scheduled_finish_date ) o100163
    WHERE  o100163."Project No" = fx100
    AND    o100161.organization_id_child = o100163.organization
    GROUP BY o100161.org_structure_version_id;

  • How to implement this? please help

    In my java class, I have a string array called strarray which hold serveral elements, some of the elements have the same value , for example, the first element is "swimming", the forth element is also swimming. I use a for loop to get each element and give it to arrayHolder which is also a array with the same size as strarray. Now, what I want is: I defined a Vector called element I want this vector to filter out the element from arrayHolder, get the name of non-duplicated name from the arrayHolder, the result should be inside the element vector (swimming,walking,running,dancing), no duplicated name. My code is like follows:
    import java.util.*;
    import java.io.*;
    public class arrayTest{
    public static void main(String arg[]){
    String[] strarray={"swimming","running","walking","swimming","dancing","running"};
    String[] arrayHolder=new String[strarray.size];
    Vector element=new Vector();
    for(int i=0;i<strarray.length();i++){
    arrayHolder[  i  ]=strarray[  i  ];
    /* What should I do next to get the non-duplicated element from arrayHolder and
    * add them into the element vector????
    I did not finnish it, since I am a little bit confused, how to implement? Need some help. thanks.
    Message was edited by:
    Mellon

    Not sure if I see the use of strArray & arrayHolder (I've not looked at your code - you might use code tags next time (check the "code" button above the message textarea), but may I suggest using a Map of some sort instead of a Vector? It will prevent duplicates for you.
    Good Luck
    lee

  • Help me:how to write this query

    i have a table employees,the data is :
    LAST_NAME DEP SALARY HIRE_DATE COMMISSION_PCT
    gets 10 4000 20060101000000
    davis 20 1500 20060303000000
    king 20 4000 20051118000000
    gets 30 5000 20040101000000
    kochhar 5000 20051201000000
    higens 40 3500 20050706000000
    my question is :
    create a query that will display the toatl number of employees and ,the number of employees hired in 2004,2005,2006.as follow:
    total 2004 2005 2006
    6 1 3 2
    thanks a lot.

    This might help you
    SQL> select * from emp;
    LAST_NAME         DEP     SALARY           HIRE_DATE COMMISSION_PCT
    gets               10       4000      20060101000000
    davis              20       1500      20060303000000
    king               20       4000      20051118000000
    gets               30       5000      20040101000000
    kochhar            30       5000      20051201000000
    higens             40       3500      20050706000000
    6 rows selected.
    SQL> SELECT COUNT(1),SUM(DECODE(SUBSTR(HIRE_DATE,1,4),2004,1,0)) "2004",
      2                  SUM(DECODE(SUBSTR(HIRE_DATE,1,4),2005,1,0)) "2005",
      3                  SUM(DECODE(SUBSTR(HIRE_DATE,1,4),2006,1,0)) "2006"
      4  FROM EMP
      5  /
      COUNT(1)       2004       2005       2006
             6          1          3          2
    SQL>Regards,
    Mohana
    I didn't see Jameel's and APC's solution. They are faster than me :)
    Message was edited by:
    Mohana Kumari

  • SQL I need help with this query Please help

    List the names of all the products whose weight unit measure is “Gram”.  Order the list by product name.  Do not use JOINS, but use the IN clause with a sub-query.
    select Name
    from UnitMeasure
    where Name= 'Gram'
    order by Name
    I did this, but it seem that the requirement is different.

    As a guess:
    Select Name from Product
    where UnitMeasure in (Select Name from unitmeasure where name = 'Gram')
    Andy Tauber
    Data Architect
    The Vancouver Clinic
    Website | LinkedIn
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
    "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

  • How to write this query using correlation subquery or non exists clause

    -- Tables description.
    --step-1- 4 employees present in EMP table.
    --step-2- each employee having 1 country_no in EMP_DOCS table.3 employees having same country_no(i.e emp's 1,2,3)
    --step-3- 1 emp document can have multiple items.In this case each employee having one each in the EMP_ITEMS table.
    --step-4- 1 EMPLOYEE  can have Multiple Documents so we have a relation between EMP_ITEMS and DOCUMENT_ITEMS.whatever items present in EMP_ITEMS those items will be inserted into DOCUMENT_ITEMS.so we have a item-item relation.
    --so we stored EMP_ITEMS id in EMP_ITEMS_REF_ID_1 of DOCUMENT_ITEMS table.
    -- step-5- DOCUMENT-INVOICE has 1-1 relation once invoice is created we stored invoice id in DOCUMENT table.
    --This is the requirement.Let's say in this example 3 employees are using same country_no and 4th employee is using another country_no
    --which is not used by other 3 employees.
    --Condtion-1:
    --if all of the employees have created INVOICE which is using same country_no of different country_no then the query should display all records.
    --Condition-2:
    --if any one of the employee not created INVOICE which is using same country_no of other employees then remaining employees also should not come in the query
    -- even though invoice is created by other employees.
    --Condition-3:
    --if any one of the employee not created even DOCUMENT  which is using same country_no of other employees then remaining employees also should not come in the query
    -- even though invoice is created by other employees.
    I hope I explain the conditions clearly.if you understand well by looking at the data i posted below may i know what is the final result should be displayed?
    create table EMP
      ID       NUMBER not null,
      TYPE     VARCHAR2(1)
    alter table EMP
      add constraint ID primary key (ID);
    create table EMP_DOCS
      ID         NUMBER not null,
      EMP_ID     NUMBER,
      COUNTRY_NO VARCHAR2(15)
    alter table EMP_DOCS
      add constraint PK_EMP_DT primary key (ID);
    alter table EMP_DOCS
      add constraint FK_EMP_DT foreign key (EMP_ID)
      references EMP (ID);
    create table EMP_ITEMS
      ID         NUMBER not null,
      EMP_DOC_ID     NUMBER
    alter table EMP_ITEMS
      add constraint PK_EMP_ITEMS_DT primary key (ID);
    alter table EMP_ITEMS
      add constraint FK_EMP_ITEMS_DT foreign key (EMP_DOC_ID)
      references EMP_DOCS (ID);
      create table DOCUMENT
      ID   NUMBER not null,
      DOCNO VARCHAR2(15),
      INVOICE_REF_1 NUMBER
    alter table DOCUMENT
      add constraint DOC_PK_ID primary key (ID);
      create table DOCUMENT_ITEMS
      ID         NUMBER not null,
      DOC_ID     NUMBER,
      EMP_ITEMS_REF_ID_1    NUMBER
    alter table DOCUMENT_ITEMS
      add constraint PK_DOCUMENT_ITEMS_DT primary key (ID);
    alter table DOCUMENT_ITEMS
      add constraint FK_DOCUMENT_ITEMS_DT foreign key (DOC_ID)
      references DOCUMENT (ID);
    create table INVOICE
      ID   NUMBER not null,
      INVOICE_NO VARCHAR2(15)
    alter table INVOICE
      add constraint INVOICE_PK_ID primary key (ID);
      INSERT INTO EMP ( ID, TYPE ) VALUES (
    1, 'A');
    INSERT INTO EMP ( ID, TYPE ) VALUES (
    2, 'A');
    INSERT INTO EMP ( ID, TYPE ) VALUES (
    3, 'A');
    INSERT INTO EMP ( ID, TYPE ) VALUES (
    4, 'A');
    INSERT INTO EMP_DOCS ( ID, EMP_ID, COUNTRY_NO ) VALUES (
    1, 1, 'INDIA');
    INSERT INTO EMP_DOCS ( ID, EMP_ID, COUNTRY_NO ) VALUES (
    2, 2, 'INDIA');
    INSERT INTO EMP_DOCS ( ID, EMP_ID, COUNTRY_NO ) VALUES (
    3, 3, 'INDIA');
    INSERT INTO EMP_DOCS ( ID, EMP_ID, COUNTRY_NO ) VALUES (
    4, 4, 'USA');
    INSERT INTO EMP_ITEMS ( ID, EMP_DOC_ID ) VALUES (
    1, 1);
    INSERT INTO EMP_ITEMS ( ID, EMP_DOC_ID ) VALUES (
    2, 2);
    INSERT INTO EMP_ITEMS ( ID, EMP_DOC_ID ) VALUES (
    3, 3);
    INSERT INTO EMP_ITEMS ( ID, EMP_DOC_ID ) VALUES (
    4, 4);
    INSERT INTO DOCUMENT ( ID, DOCNO, INVOICE_REF_1 ) VALUES (
    1, 'DOC1', 1);
    INSERT INTO DOCUMENT ( ID, DOCNO, INVOICE_REF_1 ) VALUES (
    2, 'DOC1', 2);
    INSERT INTO DOCUMENT ( ID, DOCNO, INVOICE_REF_1 ) VALUES (
    3, 'DOC3', 0);
    INSERT INTO DOCUMENT ( ID, DOCNO, INVOICE_REF_1 ) VALUES (
    4, 'DOC4', 3);
    INSERT INTO DOCUMENT_ITEMS ( ID, DOC_ID, EMP_ITEMS_REF_ID_1 ) VALUES (
    1, 1, 1);
    INSERT INTO DOCUMENT_ITEMS ( ID, DOC_ID, EMP_ITEMS_REF_ID_1 ) VALUES (
    2, 2, 2);
    INSERT INTO DOCUMENT_ITEMS ( ID, DOC_ID, EMP_ITEMS_REF_ID_1 ) VALUES (
    3, 2, 2);
    INSERT INTO DOCUMENT_ITEMS ( ID, DOC_ID, EMP_ITEMS_REF_ID_1 ) VALUES (
    4, 3, 3);
    INSERT INTO DOCUMENT_ITEMS ( ID, DOC_ID, EMP_ITEMS_REF_ID_1 ) VALUES (
    5, 4, 4);
    INSERT INTO INVOICE ( ID, INVOICE_NO ) VALUES (
    1, 'INV1');
    INSERT INTO INVOICE ( ID, INVOICE_NO ) VALUES (
    2, 'INV2');
    INSERT INTO INVOICE ( ID, INVOICE_NO ) VALUES (
    3, 'INV3');
    commit;
    -- I have written below query to satisfy above conditions but still required results are not coming..
    SELECT *
      FROM EMP E
    WHERE E.TYPE = 'A'
       AND NOT EXISTS (SELECT *
              FROM EMP_DOCS       EDOC1,
                   EMP_DOCS       EDOC2,
                   EMP            E1,
                   EMP_ITEMS      EMPI,
                   DOCUMENT_ITEMS DOCITM,
                   DOCUMENT       DOC,
                   INVOICE        INV
             WHERE EDOC1.EMP_ID = E.ID
               AND EDOC2.EMP_ID = E1.ID
               AND EDOC1.ID = EMPI.EMP_DOC_ID
               AND EDOC1.COUNTRY_NO = EDOC2.COUNTRY_NO
               AND EMPI.ID = DOCITM.EMP_ITEMS_REF_ID_1
               AND DOCITM.DOC_ID = DOC.ID
               AND INV.ID = DOC.INVOICE_REF_1);

    DB version:oracle 10g;10.2

  • Sql question how to write this query

    This is my query:
    SELECT msi.segment1 item, bsd.operation_code, bd.department_code,
    bsd.operation_description
    FROM mtl_system_items msi,
    bom_operational_routings bort,
    bom_operation_sequences bos,
    bom_departments bd,
    bom_operation_resources br,
    bom_resources bor,
    bom_standard_operations bsd
    WHERE msi.inventory_item_id = bort.assembly_item_id
    AND msi.organization_id = bort.organization_id
    AND bort.routing_sequence_id = bos.routing_sequence_id
    AND bos.department_id = bd.department_id
    AND bd.department_id = bsd.department_id
    AND bos.standard_operation_id = bsd.standard_operation_id
    AND bos.operation_sequence_id = br.operation_sequence_id
    AND bor.resource_id = br.resource_id
    AND bos.reference_flag = 1
    AND msi.organization_id = '82'
    AND bos.disable_date IS NULL
    GROUP BY msi.segment1,
    bsd.operation_code,
    bd.department_code,
    bos.operation_description,
    bsd.operation_description,
    bor.resource_code
    Which essentially produces this output:
    Item Op code Dept Description
    123 10 Warehouse Move parts
    123 20 Assembly Finish Parts
    123 30 Inspection Complete
    I need to capture when the part goes into Inspection and from where it came, so in this case, From Assembly to Inspection.
    I don't even know where to start
    Thanks for any direction

    Not sure I've got the columns names right from your example, but does this get you started at all?
    It sounds like you might need an analytic function like LAG or LEAD.
    with t as
    (select 123 item, 10 op, 'Warehouse' code, 'Move' dept, 'parts' description
    from dual
    union
    select 123, 20, 'Assembly', 'Finish', 'Parts'
    from dual
    union
    select 123, 30, 'Inspection', 'Complete',null
    from dual)
    select *
    from (
    select item, op, code, dept, description, lag(code) over (partition by item order by op) previous_code
    from t
    where code = 'Inspection';
          ITEM         OP CODE       DEPT     DESCR PREVIOUS_C
           123         30 Inspection Complete       AssemblyMessage was edited by:
    dombrooks

  • I bought a 2nd gen ipod touch without software over the internet, i cannot use any apps as i need the latest version of iOS and i don't know how to get this. Please help.

    please help

    decy95 wrote:
    When I clicked 'check for update' it just says that 2.2.1 is the current version
    It will - until you purchase iOS 3.
    Follow the link that stedman provided, and on that page, instead of choosing the link to iOS4, choose Purchase the iOS 3.1 Software Update directly from the iTunes Store. When you choose it, iTunes will open to the store and page for buying (purchasing) the update. It doesn't cost much (a few dollars although I cannot recall precisely) and it is the only way to update from you current iOS version. Once you do that, a further update to iOS 4.2.1 is free. That particular update may occur straight away, I don't know.
    By the way, iOS 4.2.1 is as high as the 2nd generation Touch can go, but don't let that put you off. I have one and although I cannot install the BBC iPlayer (because it requires iOS 5) there are many Apps that work perfectly well with iOS 4.2.1.
    decy95:
    I've just read the another discussion (to which you contributed), in which Illaass suggests that you may have a 1st generation Touch. If that is so, then your iPod will only be able to update to iOS 3.1.3. This will still need to be purchased, but be aware that many Apps require iOS 4 or higher, so your options would be more limited. So follow the link Illaass provided to confirm which model you have.
    Message was edited by: the fiend

Maybe you are looking for

  • HT201210 I have updated my iphone 5 to new ios 7 and I did not like it so I like to restore back to old ios 6.1.4, please let me know what to do

    I have updated my iphone 5 to new ios 7 and I did not like it so I like to restore back to old ios 6.1.4. please let me know how to restore to ios 6.1.4.

  • DMU 1.2 Released

    We're glad to announce the availability of Database Migration Assistant for Unicode (DMU) release 1.2 for download on OTN and My Oracle Support (MOS): http://www.oracle.com/technetwork/database/globalization/dmu/overview/index.html This update releas

  • Mac is sluggish when using FCE 2!

    When I drop a file in the viewer it plays for a few seconds and freezes. I can play the file in the canvas but it is sometimes sluggish. audio starts to drift away from the video. This is a brand new machine to me... Are there settings to dial in? An

  • Conversions issues

    hello ,           i have one requirment i need to convert time sheet information into XL Sheet  format ang i need to upload that records. pls anyone can tell me how to do this.

  • Data Issues running on iOS 5 iPhone 4

    Unfortunately, I am having data issues running a factory unlocked iPhone 4 on the Rogers Network. This problem has surfaced ever since I have upgraded to iOS 5, any tips would be grateful. Thanks. Constantly getting the error 'safari could not open t