A query please

hi sir,
i need help on queries
let say hav one table name ASL and content value like this
AcctNo ServNo ServStartDate CodeA CodeB
A4958329854 00251180741 25-Aug-1990 123 258
A4958329854 00251180741 25-Sept-1990 58 258
Z4958329854 00251100251 1-Jan-1983 58 2
The primary key is AcctNo, ServNo ,ServStartDate
i need a query to get output like this in Runtime_ASL table
AcctNo ServNo ServStartDate CodeA CodeB
A4958329854 00251180741 25-Sept-1990 58 258
Z4958329854 00251100251 1-Jan-1983 58 2
i want choose only max(ServStartDate) i mean the latest date
so how i can get this with one query
thanks in advance

wah thanks man..
this is new for me..but look cool thanks again
just wanna ask u...
is this query will work?
select AcctNo,
ServNo,
max(ServStartDate) as ServStartDate,
max(CodeA) keep (dense_rank last order by ServStartDate) as CodeA,
max(CodeB) keep (dense_rank last order by ServStartDate) as CodeB
from asl
group by AcctNo, ServNo;
since we need maximun servstartdate so why we need Keep again,juz wanna double confirm with u sir
thanks

Similar Messages

  • How to improve the performance of the attached query, Please help

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description                    Object_owner          Object_name     Cost     Cardinality     Bytes     
    SELECT STATEMENT, GOAL = ALL_ROWS                              14     1     13
    SORT AGGREGATE                                                  1     13
    VIEW                         GEMINI_REPORTING               14     1     13
    HASH GROUP BY                                        14     1     103
    NESTED LOOPS                                        13     1     103
    HASH JOIN                                             12     1     85
    TABLE ACCESS BY INDEX ROWID     GEMINI_REPORTING     RCAMSIT          2     4     100
    NESTED LOOPS                                        9     5     325
    HASH JOIN                                        7     1     40
    SORT UNIQUE                                        2     1     18
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          SITE          2     1     18
    INDEX RANGE SCAN          GEMINI_PRIMARY          SITE_I0          1     1     
    TABLE ACCESS FULL          GEMINI_PRIMARY          SITE          3     27     594
    INDEX RANGE SCAN          GEMINI_REPORTING     RCAMSIT_I     1     1     5     
    TABLE ACCESS FULL     GEMINI_PRIMARY     CAMPAIGN                    3     127     2540
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          CAMBILLING     1     1     18
    INDEX UNIQUE SCAN     GEMINI_PRIMARY     CAMBILLING_U1                    0     1

    Hello,
    This has really nothing to do with the Oracle Forms product.
    Please, send the SQL or/and PL/SQL questions in the corresponding forums.
    Francois

  • Suggest the query to this tricky query please

    Hi people,
    I just got a query which is a brain tease for me (not all).
    that is
    sql> select * from mytab;
    sql> no name
    1 asuri
    1 prasanth
    2 brian
    2 lara
    the above is query is returned by the sql;
    here 1 and 2 are duplicated values;
    now output required is
    sql>no name
    1 asuri prasanth
    2 brain lara
    Is this possible with a single sql query;
    please tell me solution
    regards
    prasanth

    How do find that it should be brian lara not lara brian..
    But any way the following will do ...SQL> select * from mytab;
    A NAME
    1 asuri
    1 prasanth
    2 brian
    2 lara
    SQL> select a,name||' '||name2 name from
    2 (
    3 select a,name,lead(name) over (partition by a order by a) name2 from mytab)
    4 where name2 is not null;
    A NAME
    1 asuri prasanth
    2 brian lara
    The names by above query can be returned as 'lara brian' and 'prasanth asuri' as there is no way telling which one is a surname..

  • Patch for bug 5397515 or alternate for query please

    Hi
    I am running following query on 10.2.0.3 but giving me internal error. Came to know that its a bug 5397515 fixed in 10.2.0.4. I want to know is there any patch available to resolve just this bug without shifting to 10.2.0.4. or any alternate for this query please??
    SELECT AB.SHIPMENT_LINE_ID, AB.TRANSACTION_ID
    FROM RCV_TRANSACTIONS AB
    WHERE AB.TRANSACTION_TYPE = 'RECEIVE'
    AND AB.SHIPMENT_LINE_ID NOT IN
    (select
    RTS.SHIPMENT_LINE_ID
    from RCV_TRANSACTIONS RTS
    WHERE (LEVEL = 2 OR
    LEVEL =
    select MAX(LEVEL)
    from RCV_TRANSACTIONS B
    start with B.TRANSACTION_ID = 133847
    connect by PRIOR B.TRANSACTION_ID = B.PARENT_TRANSACTION_ID))
    AND RTS.TRANSACTION_TYPE IN ('REJECT',
    'RETURN TO CUSTOMER',
    'RETURN TO VENDOR',
    'CORRECT')
    HAVING ABS(SUM(RTS.QUANTITY)) = AB.QUANTITY
    start with RTS.TRANSACTION_ID = 133847
    connect by PRIOR RTS.TRANSACTION_ID = RTS.PARENT_TRANSACTION_ID
    GROUP BY RTS.SHIPMENT_LINE_ID
    AND AB.TRANSACTION_ID = 133847
    regards

    >
    SELECT AB.SHIPMENT_LINE_ID, AB.TRANSACTION_ID
    FROM RCV_TRANSACTIONS AB
    WHERE AB.TRANSACTION_TYPE = 'RECEIVE'
    AND AB.SHIPMENT_LINE_ID NOT IN
    (select
    RTS.SHIPMENT_LINE_ID
    from RCV_TRANSACTIONS RTS
    WHERE (LEVEL = 2 OR
    LEVEL =
    select MAX(LEVEL)
    from RCV_TRANSACTIONS B
    start with B.TRANSACTION_ID = 133847
    connect by PRIOR B.TRANSACTION_ID = B.PARENT_TRANSACTION_ID))
    AND RTS.TRANSACTION_TYPE IN ('REJECT',
    'RETURN TO CUSTOMER',
    'RETURN TO VENDOR',
    'CORRECT')
    HAVING ABS(SUM(RTS.QUANTITY)) = AB.QUANTITY
    start with RTS.TRANSACTION_ID = 133847
    connect by PRIOR RTS.TRANSACTION_ID = RTS.PARENT_TRANSACTION_ID
    GROUP BY RTS.SHIPMENT_LINE_ID
    AND AB.TRANSACTION_ID = 133847
    >
    Are you sure this query is returning an internal error. As far as I know you can use the level keyword only when there is a connect by involved in the same level of the statement.
    For example following sql statement returns me an error.
    SQL> select * from dual where level = 2 or level = (select max(level) from dual connect by level <= 10);
    select * from dual where level = 2 or level = (select max(level) from dual connect by level <= 10)
    ERROR at line 1:
    ORA-01788: CONNECT BY clause required in this query blockI am not able to find the bug in the metalink.
    If you could copy & paste the actual error (not the contents of the trace file) and explain briefly what you are trying to achieve it will aid us in suggesting you with a solution.
    Regards
    Raj

  • HT1338 I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.

    I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.

    You can sell your existing computer using eBay, Craigslist or the venue of your choice. You could then use the proceeds to purchase a new computer.

  • PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP

    I have got three tables :
    CREATE TABLE FIRM
    (FID INTEGER NOT NULL PRIMARY KEY,
    FNAME VARCHAR(40),
    FTYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE FACULTY
    (FAID INTEGER NOT NULL PRIMARY KEY,
    FANAME VARCHAR(40),
    FATYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE EMPLOYEE
         (EID INTEGER NOT NULL PRIMARY KEY,
    ENAME VARCHAR(20),
    ESURNAME VARCHAR(20),
         EJOB VARCHAR(3),
         MASTERID INTEGER );
    This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
    I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
    I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
    I completely don,t know how to write it. Please help.

    create view hierarchy as
    select id, master_id, name from table1
    union all
    select id, master_id, name from table2
    union all
    select id, master_id, name from table3
    Then do your connect by query against hierarchy.
    It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
    Kirill

  • Need to add new column in SAP Query - Please guide me in this regard

    Dear All,
    In SAP Query, I need to put a new coulmn of each record for the difference of Billing date and PGI date as a work days.
    eg: Billing Date = 02.05.2008
         PGI Date = 08.05.2008
    Take a Variable i.e. Days = Billing Date - PGI Date that will display as 5 days by excluding Saturday and Sunday.
    After doing calculation of these work days for each record, we need a to add a new coulmn in that record as field lable as "Work Days" and display.
    Please Guide me in this regard
    Regards,
    Sateesh.

    Hi Rama,
    In SQ01 when you are in the fields (first would be attributes, when you click next it takes you to field groups, and again when you click next if takes you to fields tab) check the following menu path
    EDIT -> LOCAL FIELD -> CREATE
    You can define the formula as per your requirement and populate the field.
    Hope this is helpful.
    Thanks,
    Pavan

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

  • SQL Query -- Please Help

    Table1
    QTE_ID     SEQ_NO
    1435177     2
    1435177     5
    1435177     7
    1435177     8
    1435177     12
    1435177     14
    Table2
    QTE_ID     SEQ_NO     CMMT_CURR_AMT
    1435177     1     98500
    1435177     2     98500
    1435177     3     0
    1435177     4     98500
    1435177     5     98500
    1435177     7     98500
    1435177     8     98500
    1435177     11     59300
    1435177     12     59300
    1435177     14     59300
    The result should be
    QTE_ID     SEQ_NO     CMMT_CURR_AMT
    1435177     2     0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
    1435177     5     0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
    1435177     7     0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
    1435177     8     0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
    1435177     12     0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
    1435177     14     0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
    I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
    Please help me in writing the query.
    Thanks in advance.
    Srinivas

    WITH table1 AS
    (SELECT 1435177 qte_id, 2 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no
    FROM dual
    table2 AS
    SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
    FROM dual
    SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
    FROM
    (SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
    FROM table1 t1, table2 t2
    WHERE t2.qte_id = t1.qte_id (+)
    AND t2.seq_no = t1.seq_no(+)
    ORDER BY 1,2
    WHERE t1_seq_no IS NOT NULL
    ORDER BY 1,2
    QTE_ID T2_SEQ_NO DIFF
    1435177 2 0
    1435177 5 0
    1435177 7 0
    1435177 8 0
    1435177 12 0
    1435177 14 0

  • Row to column query ( Please its urgent)

    The query is
    SELECT
    WO.WORKORDERKEY,
    UDF1.PROJECT_MANAGER,
    UDF1.TEAM_MANAGER,
    UDF1.TEAM_LEAD,
    UDF1.CUSTOMER_COORDINATOR,
    UDF1.AVIONICS_LEAD,
    UDF1.INTERIOR_LEAD,
    UDF1.INSPECTOR,
    UDF1.MECHANICAL_ENGINEER,
    UDF1.AVIONICS_ENGINEER,
    UDF1.PLANNER,
    UDF1.PARTS_COORDINATOR,
    UDF1.LOGO_HEADER_SELECTION
    FROM
    WORKORDERS WO,
    SELECT
    DISTINCT WOUD.WORKORDERKEY,
    DECODE(UDF.LABEL,'Project Manager',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS PROJECT_MANAGER,
    DECODE(UDF.LABEL,'Team Manager',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS TEAM_MANAGER,
         DECODE(UDF.LABEL,'Team Lead',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS TEAM_LEAD,
    DECODE(UDF.LABEL,'Customer Coordinator',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS CUSTOMER_COORDINATOR,
    DECODE(UDF.LABEL,'Avionics Lead',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS AVIONICS_LEAD,
    DECODE(UDF.LABEL,'Interior Lead',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS INTERIOR_LEAD,
    DECODE(UDF.LABEL,'Inspector',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS INSPECTOR,
    DECODE(UDF.LABEL,'Mechanical Engineer',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS MECHANICAL_ENGINEER,
    DECODE(UDF.LABEL,'Avionics Engineer',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS AVIONICS_ENGINEER,
    DECODE(UDF.LABEL,'Planner',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS PLANNER,
    DECODE(UDF.LABEL,'Parts Coordinator',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS PARTS_COORDINATOR,
    DECODE(UDF.LABEL,'Report Logo/Header Selection',SUBSTR(TO_CHAR(WOUD.DATA), 1, 50),NULL) AS LOGO_HEADER_SELECTION
    FROM
    USERDEFINEDFIELDS UDF,
    WORKORDERUDFDATA WOUD
    WHERE
    UDF.USERDEFINEDFIELDKEY = WOUD.USERDEFINEDFIELDKEY
    AND UDF.LABEL IN('Project Manager','Team Manager','Team Lead','Customer Coordinator','Avionics Lead','Interior Lead','Inspector','Mechanical Engineer','Avionics Engineer','Planner','Parts Coordinator','Report Logo/Header Selection')
    AND UDF.DELETED = 0
    AND WOUD.DELETED = 0
    ) UDF1
    WHERE
    WO.WORKORDERKEY = UDF1.WORKORDERKEY(+);
    The output i am getting like:
    WORKORDERKEY     PROJECT_MANAGER     TEAM_MANAGER     TEAM_LEAD     CUSTOMER_COORDINATOR
    1     abc               
    2          ddf          
    2               rrr     
    3     aaf               
    3                    ege
    i need in single line work order key
    WORKORDERKEY     PROJECT_MANAGER     TEAM_MANAGER     TEAM_LEAD     CUSTOMER_COORDINATOR
    1     abc               
    2          ddf     rrr     
    3     aaf               ege
    Please solve my problem.

    maybe this example might be of some help.
    SQL> select * from pivot_tab;
          COL1 COL2
             1 a
             1 b
             1 c
             2 h
             2 h
    SQL>
    SQL>
    SQL> select p.col1,
      2         substr(max(substr(sys_connect_by_path (p.col2,','),2)),1,60)
      3         as col2
      4    from (select col1,
      5                 col2,
      6                 row_number() over (partition by col1 order by col1, col2) rn
      7            from pivot_tab) p
      8  start with p.rn = 1
      9  connect by p.rn = prior p.rn + 1
    10  and prior p.col1 = p.col1
    11  group by col1;
          COL1 COL2
             1 a,b,c
             2 h,h
    SQL>

  • How to rewrite this query without sub query please help me

    Hello All Good Evening,
    Could you please help me with this query, how can i write this query without sub query, or how can write this query another ways
    please help me
    select planno, status1, count(*) Counts from
    select a.ValetNO PlanNo  ,
    case 
         when JoinCode in ('00', '01', '02') then 'Actcess'
         when JoinCode in ('20', '21', '22', '23','38', '39') then
         'Secured' else 'Other' end Status1 ---, COUNT (*)
       from  dbo.ppt a(NOLOCK)  left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO  = b.ValetNO
    --group by a.ValetNO
      a group by planno, status1
    order by 2
    Thank you in Advance
    Milan

    Whats your objective here? Sorry, am not able to understand the reason for this change. 
    Try the below:(Not tested)
    ;With cte
    As
    select a.ValetNO PlanNo ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end Status1 ---, COUNT (*)
    from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
    select planno, status1, count(*) Counts from cte
    a group by planno, status1
    order by 2
    Even below:
    select a.ValetNO PlanNo ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end Status1 , COUNT (1)
    from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
    Group by a.ValetNO ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end

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

  • Suggest me the tricky query  please

    Hi
    i want to write a sql query which shown as follows:
    input inline:
    a : prasanth
    b : asuri
    output should be:
    prasanth asuri(combination of a and v variables)
    that is too without pl/sql block.
    please suggest me sql query;
    thanks in advance
    prasanth

    Hi,
    SELECT SYS_CONNECT_BY_PATH(name, ' ') "Path" FROM
    (SELECT rownum ID ,rownum-1 PID,name FROM (
    SELECT 'CHITTA' NAME FROM DUAL UNION SELECT 'RANJAN' FROM DUAL))
    where id = (2) -- this should be max Rownum
    START WITH pID=0
    CONNECT BY PRIOR id = pid
    or if it is a table
    SELECT SYS_CONNECT_BY_PATH(dname, ' ') "Path" FROM
    (SELECT rownum ID ,rownum-1 PID,dname FROM (select * from dept))
    where id = (select max(rownum) from dept)
    START WITH pID=0
    CONNECT BY PRIOR id = pid
    It is OK With you ..
    Bye
    Chitta

  • Problem while designing query please help

    Hi all,
    I have to query to find No of open cases, No of closed cases,
    Average of open cases, Average age of closed cases,
    Maximum of closed cases for a particulat Current assigne(char).
    my desired output is as follows.
    CurAssigne   Noofopencases   Noofclosed cases  Avgage(opencases) Max(open)
    CurAssigne1       10                      20                     8                              9
    CurAssigne1       18                      22                     9                              10
    My cube is consists of.
    4 Dimensions & 4 key figures
    4Dimensions are listed below.
    Business Partner{currentassigne, previousassigne,acmanager}
    createdon{createdonmonth,createdonday,createdtime}
    closedon{closedmonth,closedday,closedtime}
    Status{Latest case status-(2 status are available for each case - open,close)}
    above the objects between {} are chars.
    4 keys are listed below.
    no of cases.
    age
    first response time
    research time.
    Please help me to design this query friends..
    It's very urgent friends please help me.

    Hi,
    Please share your system configuration on which you are trying to install Ps CS6.
    Regards,
    Ashutosh
    Ps Installer QE

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

  • Problem in query : please urgent

    Hi I have this query , all the address_id i am selecting from 3 tables i want to match to another table address where i have to match adrress_id from address table to all the diffrerent address_ids from subquery . But i am getting too many values error . Please help me in writing this query.
    select * from address where address_id in (select sh.a_address_id,sh.b_address_id,ph.home_address_id,
    ph.work_address_id,cnh.site_address_id,cnh.postal_address_id,
    ph.Postal_address_id from service_history@sppmig1 sh, person_history@sppmig1 ph , customer_node_history@sppmig1 cnh where
    ph.person_id in ( select person_id from temp_customer_node_history ) and
    ph.person_id=cnh.person_id and sh.customer_node_id=cnh.customer_node_id)

    select * from address where address_id a
    WHERE exists (select 1FROM service_history@sppmig1 sh, person_history@sppmig1 ph , customer_node_history@sppmig1 cnh
    WHERE
    ((a.address_id = sh.a_address_id) or (a.adress_id = sh.b_address_id)
    or .....) and
    ph.person_id in ( select person_id from temp_customer_node_history ) and
    ph.person_id=cnh.person_id and sh.customer_node_id=cnh.customer_node_id)

Maybe you are looking for

  • Downloading table data into Excel sheet - Webdynpro Java

    Hi All, We have developed a custom webdynpro application that executes an RFC and displays data in Table UI element. We have provided a button to download the data in excel sheet. When data is huge like, total number of rows filled up in the table ar

  • Does installing many applications in Lumia 800 (Wi...

    I have installed many applications and games in my Lumia 800 (windows 7.5), but I am worried whether installing many applications in a windows phone will ultimately slows down my mobile?

  • I have 'Do Not Disturb' on, but I'm still being disturbed.

    Title pretty much says it all, but here are some particulars... * iPad mini, 32 GB, iOS 6.1.3 * Do Not Disturb is set to ON in settings. * It is it not on a schedule. It is simply set to ON. * Ordinarily, I will just turn the switch on the side of th

  • Smartform O/P Display Problem

    Hi All, Can any one help to solve this issue, i have done coading for Smartform and sending email Email is getting send but i'm unable to see the display when i select the output it is directly sending email without display , what are the parameters

  • Restore Windows

    This window appears when i try to run Edge Animate The application "Edge Animate" unexpectedly quit while trying to restore its windows.  Do you want to try to restore its windows again? Tried to Uninstall and Reinstall and still doesnt working... HE