Tuning - using the CASE statement in the WHERE clause of the query

Hi all

My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:

Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'

AND CASE WHEN
Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN 
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN 
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
END = 1
AND CASE WHEN
Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN 
TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck  = 'INCR' THEN 1
END = 1
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
Description of the table:
(Number of lines: approx. > amount 600 000 000)
Name                           Null     Type       
------------------------------ -------- ------------
ARTICLEID                      NOT NULL NUMBER(20) 
USERKEY                                 NUMBER(10) 
AVIEWORIGIN_REFID                       VARCHAR2(10)
SUCCESS_IND                             VARCHAR2(2)
ENTRY_CREATEDDATE                       DATE       
CREATED_BY                              VARCHAR2(10)
FILENUMBER                              NUMBER(10) 
LINENUMBER                              NUMBER(10) 
ACCTNUM                                 VARCHAR2(10)
AUTOCOMPLETEDTERM                       NUMBER(2)  
REQUESTDATETIME                         VARCHAR2(19)
Explain Plan
SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2224314832

----------------------------------------------------------------------------------------------------------
| Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
|   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
|   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
|*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
----------------------------------------------------------------------------------------------------------


PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

   3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
              "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
              "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
              'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
              AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
              hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
              'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
              2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
              2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
              "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
Published by: Chaitanya on June 9, 2011 02:44

Published by: Chaitanya on June 9, 2011 02:47

When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.

BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
Are compare us like with like?

Tags: Database

Similar Questions

  • Using a CASE statement in 'IN' where clause clause

    Hello

    I have a form that users see after they connect with a few items and they type or select values based on the element type. All reports in the application use these values of PAGE 1 in where clause to filter the lines.

    One of these question is "Quarter".  I have a group of radio buttons on the PAGE 1 on the P1_QTR point.

    I need to provide users a way to take the last 4, last 3, last 2 or current quarter and I need to dynamically build a clause WHERE the interactive report based on the selection in the form.

    I am trying to use the CASE as shown below and get the syntax error.

    AND QTR to (when BOX: P1_QTR = 'CURRENT' then ("T4"))

    When: P1_QTR = "LAST" then ("Q3")

    When: P1_QTR = 'LAST TWO' then ('Q3, "Q4")

    When: P1_QTR = 'LAST THREE' then ("Q2", "Q3,' T4 ')

    another ("T1", "T2", "Q3,' T4 ')

    END)

    How can I achieve this?

    Following a simple logic, try

    and QTR to

    (

    Select 'T4' double where: P1_QTR <> 'LAST '.

    Union of all the

    Select 'Q3' to double where: P1_QTR <> "in PROCESS".

    Union of all the

    Select "Q2" double where: P1_QTR not in ('CURRENT', 'LAST', "LAST TWO")

    Union of all the

    Select "Q1" double where: P1_QTR not in ('CURRENT', 'LAST', 'LAST TWO', 'THREE LATEST')

    )

  • Case statement in a WHERE clause

    Gurus,

    Im trying to avoid Union of several select statements using a CASE inside a WHERE clause. When the parameter is defined as "What's new" it is advisable to use a code and for "Update Items" another condition.

    Having a problem with the following... I know that BOX in WHEREs instructions are allowed only can not make it work for this one.

    and case  when 'New Items' = 'xxx' --p_item_status 
             then  msi.creation_date = msi.last_update_date
          when 'Updated Items' = 'bbb' --p_item_status  
             then  msi.creation_date != msi.last_update_date
          else 1=1
    end;  
    Points for correct and helpful answers!

    Published by: sreese on March 27, 2012 17:51

    Hello

    The great thing about CASE expressions, is that they allow you to use a login IF-THEN-ELSE in the clause SELECT, the ORDER BY clause or anywhere else. The WHERE clause has its own way to IF-THEN-ELSE logic, so even if you can use a CASE expression in a clause WHERRE, it usually does not help anything. You can do somehting like this:

    WHERE     (     :p_item_status        = 'New Items'
         AND     msi.creation_date  = msi.last_update_date
         )
    OR     (     :p_item_status        = 'Updated Items'
         AND     msi.creation_date  != msi.last_update_date
         )
    OR     (     :p_item_status        NOT IN ( 'New Items'
                               , 'Updated Items'
                               )
         )
    

    This guess: p_item_status is not NULL.
    If: p_item_status can be NULL, and you want to include all the lines where it is, and then change the last condition to

    OR     ( NVL (:p_item_status, 'OK') NOT IN ( 'New Items'
                                 , 'Updated Items'
                                 )
         )
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions), some values of the parameter and the expected results of these data for each value of the parameter.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • A CASE statement with additional where clause

    Hi all

    I need assistance in which this obligation clause

    Table:-balance_table

    Columns:-balance_type, balance_amount, balance_month, budget_name

    balance_type column had given 'Real' OR 'Budget '.

    Now I am trying to extract data such as: if: entered_month is Mar-2009 then before and including Mar-2009 will show real balance sheet Date and after Mar-2009 will show budget data.

    It works fine, I need to add a condition more restrict the budget name, there are several budget_name in the table for balance_type = 'Budget '.



    SELECT SUM (balance_amount), balance_type, balance_month
    OF balance_table
    WHERE balance_type =
    (CASE
    WHEN balance_month < =: entered_month
    THEN 'real '.
    ANOTHER 'Budget '.
    END
    )
    AND budget_name = 'BUDGET1.
    Balance_type GROUP, balance_month

    Stated above is erroneous because ' AND budget_name = ' BUDGET1 "clause restricts the set of data."

    Please help in contrcuting where clause 1) to sort the data according to Budget/actual and 2) for specific budgets, so budget_type = Budget

    Thank you
    Bobin

    That should do it.

    SELECT SUM (balance_amount),
           balance_type,
           balance_month
    FROM balance_table
    WHERE (balance_type = 'Actual'
           and balance_month <= :entered_month
          )
    or (balance_type = 'Budget'
        and balance_month > :entered_month
        and budget_name = :entered_budget_name
       )
    GROUP BY balance_type,
             balance_month
    ORDER BY 2
    

    See you soon
    Sarma.

  • Case statement in a where clause clause

    Hi all
    This is a query that works perfectly except when: P_value don't have any value the two result Y and N should show as a result.
    I tried with a statement of NVL but it gives me an error. Someone can help me.

    -----------------------------------
    Select
    ID
    CASE
    WHEN (colonne_1) > (column_2)
    THEN 'Y '.
    ANOTHER "N".
    END 'Test '.
    OF tabel_1
    WHERE
    (CASE
    WHEN (colonne_1) > (column_2)
    THEN 'Y '.
    ANOTHER "N".
    END
    ) =: P_value
    ---------------------------------

    When: P_value have no any value the two result Y and N should show as a result.

    It is not fair

    SELECT id, CASE WHEN (column_1) > (column_2) THEN 'Y' ELSE 'N' END "Test"
      FROM tabel_1
     WHERE (CASE WHEN (column_1) > (column_2) THEN 'Y' ELSE 'N' END = :p_value
         OR :p_value IS NULL)
    

    ??

  • No output for report of XML editor using CASE/DECODE in a Where Clause

    Hello

    I have a requirement of the company to modify an existing report that has two input parameters,
    -> p_statcode (closed status) which may have values "Y" or "n".
    -> p_overdue (flag late), which can have values of "Y" or "n".

    The flag late is a column evaluated with O/N values and it is evaluated as follows,
    ONTF_MOD_VAL(NVL (
                                         (TRUNC (SYSDATE)
                                          - (TO_DATE (oe_order_lines.attribute18,
                                                      'DD-MON-RRRR')
                                             + TO_NUMBER (fnd_lookup_values.meaning))),
                                         0
                                      ))
                            overdue_flag
    The requirement of user now is that they must be a third option for setting called p_overdue ALL,
    which by the way the output should include records with
    p_statcode is p_statcode ELSE is N AND Y OR p_overdue p_overdue is N

    In other words records with raising the Y and N for flag late must be returned regardless of the value given to the closed state.

    Original where clause contained in the data definition file is as follows,
    WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
                       AND overdue_flag = nvl(:p_overdue,overdue_flag)
    My modified code is the following,
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = (CASE
             WHEN :p_overdue = 'Y' THEN 'Y'
             WHEN :p_overdue = 'N' THEN 'N'
             ELSE overdue_flag
             END)
    OR
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)
    Both approaches have the same problem.
    The output is in EXCEL format. The modified query works very well for p_overdue as Y or N but when p_overdue is passed as ALL he returned a blank EXCEL sheet with just exit report column headings.
    Any help regarding, why is this the case? What's not in my approach?

    Kind regards
    Vishal

    unclear on p_overdue = ALL
    P_overdue = ALL on what necessary values?

    try sth like

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
    )
    

    for overdue_flag, which has more then 'Y' values of "n".
    If overdue_flag that in ('Y', ' don't) then

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL'
    )
    
  • Problem in the export using the QUERY functionality

    Problem in the export using the QUERY functionality


    I'm trying to export some rows in a table using the query functionality
    and I have some errors... I'm using the syntax is

    system@orcl QUERY = scott.emp expdp: '"WHERE emp_no = 123455" '
    DIRECTORY = data_pump_dir DUMPFILE = data_pump.dmp
    LOGFILE = data_pump_12345.log INDEX = n

    Can someone tell me please the problem with that statement

    I also tried to use the simple export

    exp file system@orcl = orcl_export.dmp log = orcl_export.log
    tables = Scott.EMP index = QUERY = n------"WHERE emp_no\ = 123455\"

    and this error

    EXP-00008: ORACLE error 904
    ORA-00904: identify invalid

    My os is Solaris
    Please let me know what the problem

    Hello

    Try to create parfile and use that, otherwise, you will need to escape each clause correctly to run exp or expdp successfully.

    test.par

    tables=emp
    query="WHERE emp_no=123455"
    
    or
    tables=myobjects
    query="WHERE owner='SYS'"
    
    $> exp username/password parfile=test.par
    
    Export: Release 10.2.0.1.0 - Production on Thu Mar 19 10:17:48 2009
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining Scoring Engine options
    Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
    
    About to export specified tables via Conventional Path ...
    . . exporting table                      MYOBJECTS      22650 rows exported
    Export terminated successfully without warnings.
    

    Concerning

    Published by: OrionNet on March 19, 2009 10:21

  • Inserting data by using the query

    Hello

    In a book, I read the Sub statement:

    Inserting data by using the query (DML)

    If the user wants to transfer data from a table to another table in the insert statement are used independently of data that can be processed or not processed form.

    Can someone clarify what is the significance of this (processed or unprocessed form).


    Thank you.

    Why don't you ask the author of the book.

    How can we know what the author means when you take a quote out of context and don't provide any reference so that we can see exactly what is shown to you.

    I can only imagine that they are referring to data that are queried directly, "like what", another table, or who was interrogated and manipulated before be inserted.

  • the search for empty cells by using the query designer

    Hello

    I'm trying to exclude empty cells in a field (by using the Query Builder), and I did:

    xDocumentSource < match > "CDL".

    < AND >

    < NOT > (xRelatedMsgid < match > "" "")

    but it does not work. I tried "NULL", but it does not work either. Could someone tell me how to do it (or where I can find examples of queries).

    Kind regards

    Iwona

    https://blogs.Oracle.com/Kyle/entry/searching_for_null_values_ucm

  • Using the QUERY parameter in exp/expdp

    Hi, I've faced a nite last question.
    IM currently using Oracle 10 g (10.2.0.4) OS - MS Windows Server 2003

    I want a dump of tables to export multiple schemas. say (acb.m1, pqr.b2, xyz.b1)

    Each table has a minimum lines of 2,000,000,

    And I want to just the initials 10 rows in each table of export

    Is it possible that I can do this...

    Please answer.
    Thanks in advance

    Export tables in multiple schemas is not supported in Data Pump until 11.1.0.7. So if you're on 10g, you will need to run multiple commands expdp. For only 10 lines of each table, use the query parameter

    Query = "where rownum"<>

    This will apply to all the tables you export.

    I hope this helps.

    Dean

    Published by: Dean WINS January 30, 2012 08:42

  • DataPump import by using the query

    Hello

    I need to import data by filtering using the query. can anyone help?

    Thank you

    Hello
    example of

    expdp HR/hr = emp QUERY:'"WHERE dept_id > 10 AND sal > 10000"' NOLOGFILE = y DIRECTORY = dpump_dir1 DUMPFILE = exp1.dmp

    Impdp HR/hr DIRECTORY = dpump_dir1 DUMPFILE = expfull.dmp QUERY = departments:'WHERE department_id «»< 120"'="" nologfile="">

    See this link

    http://download.Oracle.com/docs/CD/B13789_01/server.101/b10825/dp_import.htm

  • IMPDP | Possible using the query option

    HI PPL,

    I wanted to know if IMPDP is possible by using the query option, as I took full expdp dump of the mentioned table and want to import only select lines.

    Impdp arup/arup directory = demo_dir dumpfile = employees.dmp
    Query = employees:------"" where salary\ > 10000\ order of salary "tables used ="

    version: 10 gr 2
    platform: UNIX

    concerning

    Obviously, it will be slow if you are using the query option, because IMPDP must import only the data that meets the criteria; It of why we export only limited data (one or two tables as needed) and import them completely.

    Concerning
    Girish Sharma

  • List of virtual machines in TIME using the query service

    Someone been able to use the query service to produce a range of virtual machines in a paralytic? I don't see all the attributes on the VclQueryadminVMField that reference the vApp.

    I log in the org of system.

    Any help would be appreciated.

    Name of the action: getVAppVms

    Entry: VAPP (vCloud:VApp)

    Output: Array / vCloud:VM

    Script:

    var vcdHost = vApp.getHost();
    var vms = new Array();
    
    var queryService = vcdHost.getQueryService();
    expression = new VclExpression(VclQueryVMField.CONTAINER, vApp.getReference().href, VclExpressionType.EQUALS);
    filter = new VclFilter(expression);
    params = new VclQueryParams();
    params.setFilter(filter);
    
    var resultSet = queryService.queryRecords(VclQueryRecordType.VM, params);
    while (resultSet != null) {
        var records = resultSet.getRecords(new VclQueryResultVMRecord());
        System.log(records.length + " VM records found");
        for each (var record in records) {
         var vmRef = new VclReference();
         vmRef.href = record.href;
         vmRef.name = record.name;
         vmRef.type = record.type;
         vms.push(vcdHost.getEntityByReference(VclEntityType.VM, vmRef));
        }
        resultSet = resultSet.getNextPage();
    }
    
    return vms;
    

    This is what made our team (more precisely - Christophe)

  • Not able to change the password by using the query. Select APPS.fnd_web_sec

    Not able to change the password by using the query.
    Select APPS.fnd_web_sec.change_password ('username', 'password') 'RES' double;

    Can someone tell why and what privileges and subsidies have flexibility to the user non-apps while it can change the password using fnd_web_sec.change_password.



    Concerning

    the information above does not solve my problem, I get the message

    Because you do not have permission on all objects that are referenced by the API (see below).

    Select FND_WEB_SEC. CHANGE_PASSWORD ('MARSHAD', 'mohammad @123') "RES" of the double

    *

    ERROR on line 1:

    ORA-00942: table or view does not exist

    ORA-06512: at the 'APPS '. FND_CORE_LOG', line 25

    ORA-06512: at the 'APPS '. FND_CORE_LOG', line 432

    ORA-06512: at the 'APPS '. FND_PROFILE', line 110

    ORA-06512: at the 'APPS '. FND_SSO_MANAGER", line 227

    ORA-06512: at the 'APPS '. FND_WEB_SEC', line 1425

    ORA-06512: at line 1...

    can you please list me what are the grants and other Jules Destrooper I should give to a user so that he can change password.

    I don't have the list of objects and you should get yourself by consulting the site code and eTRM API.

    by changing the DDT in the user non-apps after the grant, will, it may be able to change the password.please tell this syntax is correct or not.
    Select applications. FND_WEB_SEC. CHANGE_PASSWORD ('user', 'pwd') "RES" of the double

    What is the point of using 'FND_WEB_SEC. CHANGE_PASSWORD' and not FNDCPASS or FND_USER_PKG API?

    Thank you
    Hussein

  • using a Case statement to display the values of column even as table headers

    I have a database that has been set up kind of tricky, in that some tables are made up of columns that are field names and one link to another table that contain the data for these field... also names there ID displays as many lines instead of as a row of data. I would like to write a query to extract that information and display it as one line for each ID.

    example: table 1

    ID, name, itemresponse and itemcode, Description

    Dee Jones Childrens Hospital 123 SITE location

    123 dee Jones, Date of appointment next NEXTAPPT 22/04/2014

    123 dee Jones was on bedrest NOSHOW reason do not show

    I would like to have the display of data as a record on this same patient, instead of as 3 separate registers (with the Description column in table 1

    Table 2

    ID, name, place, Date of the next meeting, show no reason

    123 dee Jones Childrens Hospital 22/04/2014 was the bed rest

    I have included the code I worked on below my question, for me to get the desired results should I use the Case statement and it's the right way to do it below?

    (SELECT
    PAT.ID "PATIENT ID."
    PAT. FIRST | » '|| PAT. "PATIENT FIRST NAME."
    PAT. "PATIENT DOB," DATE_OF_BIRTH
    DS. Date 'Date of inpatients ',.
    Dai. ITEM_CODE "Item Code",
    Dai. DESCRIPTION "Description."
    Siad. ITEM_RESPONSE,

    Max (CASE WHEN dai. ITEM_CODE IS "SITE" THEN DAI. Decription
    ANOTHER NULL
    END) AS "name of the hospital."

    Max (CASE WHEN DAI.) ITEM_CODE IS 'NEXTAPPT' THEN DAI. ITEM_Description
    ANOTHER NULL
    END) AS 'next Appt Date. "

    Max (CASE WHEN DAI.) ITEM_CODE IS "LASTDATE" THEN DAI. Description
    ANOTHER NULL
    END) AS 'last visit Date.

    Max (CASE WHEN DAI.) ITEM_CODE IS 'NOSHOW' THEN DAI. Description
    ANOTHER NULL
    END) THAT "the reason has not shown".

    Of
    (PAT.ID "IDENTIFYING PATIENT",
    PAT. FIRST | » '|| PAT. "PATIENT FIRST NAME."
    PAT. "PATIENT DOB," DATE_OF_BIRTH
    DS. Date 'Date of inpatients ',.
    Dai. ITEM_CODE "Item Code",
    Dai. DESCRIPTION "Description."
    Siad. ITEM_RESPONSE

    Of

    dm_sessions Ds,
    dm_session_assessments dsa,
    DAS dm_admin_sections,
    dm_session_assessment_items Siad,
    Dai dm_admin_items,
    Po Patient_Orders,
    Inventory inv,
    Patients_Table PAT
    dm_admin_categories CAD

    where dsa.session_Id = ds.session_Id
    and PAT.ID = ds. Patient_ID
    and dsa.excluded_assessment =' no
    and dac.category_code = 'OPEN'

    and dsa.section_id = das.section_id
    and das.category_id = dac.category_id
    and das.section_code = 'northwest'
    and dai.section_id = das.section_id
    and dsai.item_id = dai.item_id
    and dsai.session_assessment_Id = dsa.session_assessment_Id
    and dsai.excluded =' no
    - and Dai.ITEM_ID = Dsai.ITEM_ID
    and Dai.ITEM_CODE IN ('SITE', 'NEXTAPPT', 'LASTDATE', 'NOSHOW')
    and po.patient_ID = ds.patient_ID
    and in. NDC_NO = inv. NDC_NO
    and inv. TDRUG_ABBREV = in. DRUG_ABBREV

    PAT.ID GROUP, PAT. FIRST | » '|| PAT. LAST, PAT. DATE_OF_BIRTH, ds. Date, dai. ITEM_CODE, dai. DESCRIPTION, Siad. ITEM_RESPONSE))

    Hello

    DATE is not a very good name for a column.  Use something like EVENT_DATE, that will not be confused with a keyword from Oracle, instead.

    I don't see something like this column in the CREATE TABLE statement.  He will always be the same value on all lines?

    Here's a way to get the results you requested:

    SELECT id

    first name | ' ' || LastName AS name

    Date of birth

    MAX (CASE WHEN item_code = "NEXTAPPT", THEN item_response END) AS next_appointment,

    MAX (CASE WHEN item_code = "LASTDATE" THEN item_response END) AS last_visit_date,

    MAX (CASE WHEN item_code = "SITE" THEN item_response END) AS location

    FROM mytable1

    GROUP BY id, firstname, lastname, dob

    ;

    Of course, I can't test it very well until you post INSERT statements for the sample data.

    I guess that 2 or more lines of the entry have the same id, then they will necessarily be first name last name, the name and date of birth, too.  No doubt they are standardized in your actual tables.

Maybe you are looking for

  • Pavilion m8357 need drivers

    Hi I have a HP m8357 with windows vista. I uninstalled vista and installed xp but none of my drivers will be installed. Is there a link for the drivers to lift this pc and rerun

  • Created recovery 2 discs but for the installation of the OS is used only

    I went to a friends this afternoon and he made the recovery discs and everything went well, 2 discs were made.Now, he has just phoned to say he used the discs on his laptop computer, but only one was used then why do 2, is it necessary to n2.Ken

  • Motorola Service App update

    Motorcycle G (2nd gen) a Motorola Update service app? I see all over the internet that Moto G 'Motorola Update Service' app updated so that it can receive the OTA for Lollipop.

  • Pavilion 17-g101dx: remove Cyberlink programs

    I just bought a new HP Pavilion and it has four associated programsin Cyberlink. I use Irfanview and Windows Media Player formy display and ripping operations. I don't watch DVDs or doall complicated image change. It would be safe to get rid of these

  • E5-521G60BX laptop computer supports audio HDMI?

    I checked the playback devices and there is only a single device, which is the default speakers on the laptop. I checked the devices disconnected and disabled and still nothing appears. I think it has something to do with the double graphics or somet