How to avoid using MAX (CASE... WHEN) in a subquery

Hi everyone, for all of you gurus plsql, I have a question:

SELECT a.id,

B.SID,

b.Name,

....

(CASE WHEN sub_c.value_c = '2015' AND a.code > = 1111 'output value is' | a.value_a ELSE 'Random value' END) output

FROM table_a a,.

Table_B b,

...

(SELECT C.a_id

MAX (CASE WHEN c.code <>'A'

THEN c.value

Value_c END)

OF table_c

GROUP BY c.a_id

) sub_c

WHERE a.id = b.a_id

AND a.id = sub_c.a_id (+)

If they all want table_c a_id, and WHEN the condition is not convinced that they still want this allowance a_id even with null for value_c.

I tried to outline the most important parts, so the question is: is there a way to avoid using this construction MAX - CASE somewhat expedite this request?

Thanks for a ton to all those who have taken need to watch this!

You can move the CASE WHEN c.code <> 'A' predicate in the where clause table_c. Index c.code, then use

Max (c.value)...

where c.code <> "A".

If you have a lot of 'A' values that can speed things up.

Tags: Database

Similar Questions

  • How to avoid make records duplicate when you save a series?

    How to avoid make records duplicate when you save a series?

    When you schedule a recording for a TV series, Media Center automatically records episodes based on the options you set here.

    1. click the Start button, click all programsand then click Windows Media Center.

    2. on the Media Center start screen, navigate to tasks, click settings, click TV, click recorderand then click default record.

    3 scroll to the series as the default record section.

    4. do one of the following:

    ·         Under Show type, click the plus sign (+) or minus (-) button to record only new episodes, reruns or direct episodes.

    ·         Under channels, click the plus (+) or minus (-) record button present in this series on any channel, or on a specific channel.

    ·         According airtime, click the plus sign (+) or minus (-) button record shows in this series at any time, or only at a specific time.

    ·         Under the keep up to, choose how many records in this series to keep before older episodes are automatically deleted.

    5. click on Save.

  • How to avoid the u letter when you type ' u?

    Hello community,

    I need to write ' u , but it automatically replaces these two letters by u on selection of keyboard we International PC.

    Can you suggest me how to avoid it?

    Thanks in advance,

    Gomez

    What exact keystrokes you type?

  • How to avoid using the library native ttJdbcCS when connecting to remote host?

    I'm testing the Java program with the product that limits the use of native libraries.
    I use the 'client' mode to connect to TimesTen DB (which is done by using the plug, not the shared memory).

    It seems that even in client mode TimesTen JDBC driver calls the library native ttJdbcCS when doing remote queries.
    Why it does not use Java sockets? What is necessary for the native library?
    Is it possible to eliminate the use of native libraries in client mode of the JDBC TimesTen driver somehow?

    I fear that it is not possible to eliminate the use of native code for TimesTen libraries. Both direct drivers and customer are drivers of type 1 (JDBC/ODBC bridge). In both cases the JDBC driver Java code called NYI optimization library ttJdbc/ttJdbcCS and that the library in the direct or client ODBC driver (also called native code).

    If you want to use TimesTen then you must be able to allow the use of these native code libraries. The only other alternative is to implement your own client/server mehcanism such that you can put your own component 'server' on the machine running TimesTen and then use pure Java to communicate with this component of the 'customer '. Generally, it is however a lot of work.

    Chris

  • How to disable Edit/Clone/case when transaction obtained ceratin in apex 4.2

    Hi all

    In our application, we have designed a screen using interactive report as shown below, in this report when they click on the checkbox and click the middle button we are what makes this transaction as being inactive and red color display. Requirement is now this line had to be disabled once the record was ceratin.

    1. below is screenshot of reference

    2 when they select the checkbox and click the ceratin that she will change in different as on the first row, now that the rank we now need to disable this, since this product has been produced de-activated.

    3 below used concept to achieve color, using dynamic action, we put in place this

    $('td[headers="Active_Flag"]').each(function() {  
      if ( $(this).text() === 'N' ) {  
        $(this).closest('tr').find('td').css({"background-color":"#EEA196"});
      } 
    });
    

    4. the logic of inactive code

    update t_test
                 set active_flag='N',
                      inactive_date=sysdate
                WHERE prod_map_id = to_number(apex_application.g_f01 (i));    
    

    Could you please let me know how to disable it.

    Kind regards

    Sruthitamiri

    Sruthi Tamiri wrote:

    I created an application in apex.oracle.com, please find necessary details, when you click on the checkbox and click Delete active, I call process of having ename like "N", then entire line should be disabled, because these have become now in use. Also, I gave the icon change, but total feature I didn't explain, that won't hurt i., e will redirect us to another page, where they changed the required fields, in this case I'm showing only a blank page. Once the entire line is turn off, it will not be able to click the icon change as well.

    Using CASE expressions in the report query to conditionally exclude links and lines disabled checkboxes and add a hidden (EMPNO) key column that can be referenced as a parameter in the conditional link:

    select
        case ename
          when 'N'
          then
            null
          else
            ''
        end "Edit"
      , ename
      , job
      , case ename
          when 'N'
          then
            null
          else
            apex_item.checkbox2(
                p_idx => 1
              , p_value => empno)
        end checkbox
      , empno
    from
       emp
    

    The column change Display Type value Standard report columnand the column Link Text link #Edit #.

  • How to avoid the focus problem when browsing via browser back button

    Hello

    I am facing a problem in setting focus on the buttons.
    Please see application: http://apex.oracle.com/pls/otn/f?p=47869:2

    login details:
    Workspace: vsanthanam
    user: vijay
    PSWD: apex_demo

    In this application, I have 2 pages.
    #2 has the "submit" button
    Page no. 3 contains the Cancel button

    The two buttons are basic HTML and can be accessed using access key ALT + s and ALT + c.

    The problem is:
    When I go back to the previous page (pgid #2) of the application using back button of the browser pgid IE #3.
    due to the onFocus event located in the button "submit", control returns to pgid #3.

    Is there a possible way to set the focus to other elements. so that whenever IE brower back button, application would stay in
    page #2.


    I took approaches:
    -------------------------
    If we use onclick, onfocus instead and then the problem remains because we have onfocus = "this.click (); in equipping the Accesskey.
    Another way is onKeyup event. If we use onKeyup, we can avoid this browser back problem, but disappears from the access keys functions.

    Pointers on this would be a great help.

    Thank you very much
    -Vijay

    PLEASE NOTE: I have created intentionally two buttons on each page. It is necessary to have HTML buttons with the key features of access,
    otherwise application gives a few flaws in HTML accesskey.

    Hi Vijay,

    Crikey, aren't annoying browsers! It took a while to get out, but I've updated your SUBMIT1 button attributes:

    class="t20Button" AccessKey="s" tabindex="-1" onclick="javascript:this.blur();doSubmit('SUBMIT1');" onfocus="javascript:this.blur();doSubmit('SUBMIT1');"
    

    Note that I removed the spare semicolons you after each attribute - these are only required in javascript code.

    The important point to note are the statements of "this.blur" () - this tells the browser to move away from the current item to the next. On your page, only for this purpose, I have added a text element of Temp - I am assuming that your actual page will have at least one other element on the page that will accept the focus? Everything gets focus of the call "this.blur ()", should be the element with focus when the Back button is used.

    Andy

  • How to avoid to create images when importing duplicate?

    I doubt that it is the correct method or better to import/organize my photos, because it creates additional work I would like to avoid.  I'm looking for a solution.

    I do the following:

    • Copy all my photos from my SD card in my folders organized on my external hard drive.
    • Open Lightroom and import photosfrom my external hard drive.

    What happens is that Lightroom creates an image duplicated on my Mac in my pictures folder. At this point, he referred to this directory and not my external hard drive. What I end up doing deletes the pictures in my photos folder.  So I connect all my photos in Lightroom on my external drive.

    As you can imagine, it becomes tedious to do this every time I have import in Lightroom.

    My idea situation is Lightroom NOT to reproduce images or put them in any folder, but simply refer to those that I chose when importing to my external hard drive.

    Any help would be much appreciated.

    It's probably because you select the option COPY the top of import dialog when you should be by selecting the Add option.

    COPY the images of copies from one place to another and to import them.

    ADD add just the images in the LR catalog where they are currently.

    There is also the possibility of "make the second copy to:" on the side right of the dialog import but this option is only available with either COPY it, MOVE or COPY as DNG options. You need to add the option to add images in the catalog file LR in the place where they are already on your external drive.

  • How to avoid overwriting the italics when you apply paragraph styles?

    First of all, let me say thank you to the community of Adobe's Forum for the great help over the years! You Rock! 9 times out of 10 you nail!

    OK, so I have a long document full of italics, bold and accents. Successfully, I imported the text in MS Word and kept these text features using the import options. But now, when I go to apply paragraph styles, the italics are lost. Is it possible to implement paragraph styles so that they maintain Roman, italic, bold and also special characters like accents? Thank you!

    Hi David: I just put upward (and record) queries for search/replace that I of course after you import all text. For example, I have one that is italic in the document and it goes to a character called italic style. Once I saved queries, it is very fast to run on all the stories at the same time. And once the local formatting is managed through character styles, it is intact by assigning paragraph styles.

    ~ Barb

  • How to avoid using fractions of EPUB available pixels fixed.

    Apple said to avoid the use of fractional pixels for letter spacing, font size and text placement. Since then, sometimes in the conversion to html and css formatting. Is there a way I can control this?

    Someone had their book rejected because of this?

    Thank you!

    It is perhaps not the droids you are looking for, but a way to check after the fact would be to create a copy of your epub, rename the epub to [epubnam] .zip (change .epub to .zip) and then find the .0px, .1px, .2px generated css file... (if you're handy with regular expressions, you could do a little better by looking for------.) ([0-9] * px, I checked it quickly to regexpal.com, but more robust tests may be in order)

    If you find a fractional value, you could "fix" no closest fractional value which is not trash your design and repackage the epub.

    FWIW, I did a quick scan through my epub css and can't find any decimal values.

  • How to avoid using oracle.jdbc.driver.OracleConnection

    I am new to Java, but recently, I have a project on support.

    Problem:

    solution worked on the 1.4 jvm, now on 1.7.

    Respectively, the oracle.jdbc.driver.OracleConnection class has been used.

    Now, I need class oracle.jdbc.OracleConnection to use CLOB.createTemporary (), but... I can't.

    According to the docs, just replace in the code and config files a declaration of the class on another. But I replaced all in all the files of configuration of no. and anyway, no there wasn't that oracle.jdbc.driver.OracleConnection was created. (there is no explicit declaration of the type of connection in the code, everything is configured in the config files)

    Project uses marven, mybatis - 3.1.1. Database: oracle 9

    Driver: ojdbc14 - 9.2.0.5.jar contains two classes: the oracle.jdbc.driver.OracleConnection (for backward compatibility) and oracle.jdbc.OracleConnection.

    The question is what do I need to use a second instead of the first.

    Maybe there are a few java cache? I do not know...

    Everyone knows?

    I solved the problem!

    This thread helped me: https://forums.oracle.com/thread/556426 ("I have to use classes12.zip for this work.")

    The main problem was the jdbc driver - I tried all the ones I found on the page of download of oracle and the only factor that does the job was classes12.jar (Oracle Database 10g Release 2 (10.2.0.1.0)). I replaced it in 'ORACLE_HOME\jdbc\lib\' and 'apache-tomcat\lib\.

    Each driver has its own bugs, and I also did different things, so I can't say that any replacement driver is enough. Te I changed the time zone database, run the tzupdater, vm set param - Duser.timezone = ""-07:00 ", may be something else."

    Thank you very much for the answer so detailed!

  • How to avoid using the 'form' tag

    Hi all

    Is it possible to call a form of my FORMS_PATH site from the browser without using the format of tag in the URL?

    for example, this is my URL to call the form master.fmx--> http:// < machine >: < port >/forms/frmservlet? form = master.fmx, is what I want to call it without using the format of tag after the? in the URL.

    Thank you.

    You can configure your formsweb.cfg file to include a section for your application.

    Lets say you have a section called myApp in the formsweb.cfg file,
    Then you can use http:/.../forms/frmservlet?config=myApp to call the application

    Note: If ssoMode = true in the related section of the formsweb.cfg for the MyApp, then the signature will only kick in the first

    You can use a specific environment file (a copy of the default.env file to your app) and then specify this environment file in the section of the formsweb.cfg file MyApp.

    [myApp]
    envFile = myApp.env
    ssoMode = true
    form = MyAppFirstForm
    pageTitle = MyApp
    ...

    Hope this is useful

  • How to avoid using several golds?

    I have a query that returns a number where I have to change some text if this number fits my criteria... the code looks like this (just an example)

    < name cfquery = "getNumber" datasource = "#Application.dsn #" >
    Select SomeNumber
    Users
    Where blah = blah
    < / cfquery >

    Is there a cleaner way to do this? (see code below)

    Thanks for your help.

    Set the values you want to add to a list, then do this:


    Found!

    Did not find it

  • SDO_NN cannot be assessed without using the index when put inside subquery

    Hi all

    I met a problem when you use the function sdo_nn to find the nearest neighbor. Here is my scenario:

    _ I have 2 customer and store tables.

    Customer table _ a client_ID and a 2D sdo_geom point

    _ Store table has store_ID and a 2D polygon sdo_geom.

    In the beginning, I have this query to find the nearest store to each customer as below:

    Select s.STORE_ID, c.CLIENT_ID

    store customer, s c

    where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE";

    _It works as expected when it returns a table showing the nearest store each customer.

    _Now I want to count the number of customers who have the same nearest store:

    Select / * + INDEX (store store_spatial_idx, client_spatial_idx client) * / count (nearest_store. CLIENT_ID)
    from (select s.STORE_ID, c.CLIENT_ID
    store customer, s c
    where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE") nearest_store
    Group of nearest_store. STORE_ID;

    This query generates the following error:

    Error report-
    SQL error: ORA-13249: SDO_NN cannot be assessed without using the index
    ORA-06512: at the 'MDSYS. MD", line 1723
    ORA-06512: at the 'MDSYS. MDERR", line 17
    ORA-06512: at the 'MDSYS. PRVT_IDX', line 9
    13249 00000 - '%s '.

    I'm pretty new to spatial databases and hope get help to go further. Thank you in advance!

    Hello Pinball,

    Oracle space tends to be a quite complex with many variables and moving parts.  We chatted about the group to a sort of FAQ or guidelines to help people like you submit questions that actually answers.  First of all, you really have to tell us the version of Oracle you are using.  Particularly the problems involving the optimizer, version down to the exact defined patch number is a good idea.  Secondly, you took the time to submit the question so I guess you want a response.  If you really want to see the answer and then providing an example is one of the most important things that you can do.  I'm going to do here for you, but in general people on this forum come and go and are often pushed into lurkitude, so if you want the coax to provide you with an example of work is the key.

    DROP TABLE store1 PURGE;
    CREATE TABLE store1(
        store_id INTEGER NOT NULL
       ,shape    MDSYS.SDO_GEOMETRY
       ,PRIMARY KEY(store_id)
    );
    
    DROP TABLE client2 PURGE;
    CREATE TABLE client2(
        client_id INTEGER NOT NULL
       ,shape    MDSYS.SDO_GEOMETRY
       ,PRIMARY KEY(client_id)
    );
    
    CREATE OR REPLACE PROCEDURE seeder(
        p_client_count IN NUMBER
       ,p_store_count IN NUMBER
    )
    AS
      sdo_foo MDSYS.SDO_GEOMETRY;
      int_counter NUMBER;
      FUNCTION random_point
      RETURN MDSYS.SDO_GEOMETRY
      AS
          num_x1 NUMBER;
          num_y1 NUMBER;
    
      BEGIN
          num_x1 := dbms_random.value(-179,179);
          num_y1 := dbms_random.value(-89,89);
    
          RETURN MDSYS.SDO_GEOMETRY(
              2001
             ,8265
             ,MDSYS.SDO_POINT_TYPE(
                  num_x1
                 ,num_y1
                 ,NULL
              )
             ,NULL
             ,NULL
          );
    
      END random_point;
    
    BEGIN
      int_counter := 1;
      FOR i IN 1 .. p_client_count
      LOOP
          -- Create a client point
          sdo_foo := random_point();
          INSERT INTO client2
          VALUES (
              int_counter
             ,sdo_foo
          );
          int_counter := int_counter + 1;
    
      END LOOP;
    
      int_counter := 1;
      FOR i IN 1 .. p_store_count
      LOOP
          -- Create a store polygon of some kind
          sdo_foo := MDSYS.SDO_GEOM.SDO_ARC_DENSIFY(
              MDSYS.SDO_GEOM.SDO_BUFFER(
                  random_point()
                 ,5000
                 ,0.05
              )
             ,0.05
             ,'arc_tolerance=0.05'
          );
          INSERT INTO store1
          VALUES (
              int_counter
             ,sdo_foo
          );
          int_counter := int_counter + 1;
    
      END LOOP;
    
      COMMIT;
    
    END seeder;
    /
    
    BEGIN
      seeder(10000,200);
    END;
    /
    
    BEGIN
      INSERT INTO user_sdo_geom_metadata(
          table_name
         ,column_name
         ,diminfo
         ,srid
      ) VALUES (
          'STORE1'
         ,'SHAPE'
         ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05))
         ,8265
      );
    
      COMMIT;
    
    EXCEPTION
      WHEN OTHERS
      THEN
          NULL;
    
    END;
    /
    
    BEGIN
      INSERT INTO user_sdo_geom_metadata(
          table_name
         ,column_name
         ,diminfo
         ,srid
      ) VALUES (
          'CLIENT2'
         ,'SHAPE'
         ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05))
         ,8265
      );
    
      COMMIT;
    
    EXCEPTION
      WHEN OTHERS
      THEN
         NULL;
    
    END;
    /
    
    CREATE INDEX store1_spx ON store1
    (shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX
    NOPARALLEL;
    
    CREATE INDEX client2_spx ON client2
    (shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX
    NOPARALLEL;
    
    /* Works as expected */
    SELECT
    s.store_id
    ,c.client_id
    ,MDSYS.SDO_NN_DISTANCE(1)
    FROM
    store1 s
    ,client2 c
    WHERE
    MDSYS.SDO_NN(
        s.shape
       ,c.shape
       ,'sdo_num_res=1'
       ,1
    ) = 'TRUE';
    
    /* No worky? Works for me */
    SELECT
    ns.store_id
    ,COUNT(ns.client_id)
    FROM (
       SELECT
        s.store_id
       ,c.client_id
       FROM
        store1 s
       ,client2 c
       WHERE
       MDSYS.SDO_NN(
           s.shape
          ,c.shape
          ,'sdo_num_res=1'
          ,1
       ) = 'TRUE'
    ) ns
    GROUP BY
    ns.store_id
    ORDER BY
    ns.store_id;
    

    So I wrote this about 12 c (12.1.0.2.0) and everything works fine for me.  Then I moved back from 11 GR 2 (11.2.0.4.0) and of course, there are questions.  So I guess that you don't use flavor of 11g.  So at this point we can look at the docs and see for 11g, have you often need to specify which table is the head and that is the one that has the spatial index to use.
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_operat.htm#SPATL1032

    Its rather interesting that the optimizer of 12 c knows what you want, when I had to squint myself at your request and to play a little with the refining.  Note that SDO_NN is sensitive, because the geometry of the main table should come second in the operator.  I did not know that on the top of my head.

    
    SELECT
    /*+ LEADING(c) INDEX(s store1_spx)  */
     s.store_id
    ,c.client_id
    ,MDSYS.SDO_NN_DISTANCE(1)
    FROM
     store1 s
    ,client2 c
    WHERE
    MDSYS.SDO_NN(
        s.shape
       ,c.shape
       ,'sdo_num_res=1'
       ,1
    ) = 'TRUE';
    
    SELECT
     ns.store_id
    ,COUNT(ns.client_id)
    FROM (
       SELECT
       /*+ LEADING(c) INDEX(s store1_spx)  */
        s.store_id
       ,c.client_id
       ,MDSYS.SDO_NN_DISTANCE(1)
       FROM
        store1 s
       ,client2 c
       WHERE
       MDSYS.SDO_NN(
           s.shape
          ,c.shape
          ,'sdo_num_res=1'
          ,1
       ) = 'TRUE'
    ) ns
    GROUP BY
    ns.store_id
    ORDER BY
    ns.store_id;
    

    So I think that is your answer.  Give it a shot and see if this fits the Bill.  Of course, moving to 12 c would be useful for such things.  It would be interesting to collect more examples of this kind of space thing where 12 c is the answer. Also, would be nice if we could mark somehow this discussion as applying only to 11g and earlier versions.

    See you soon,.

    Paul

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

  • The values just don't not properly using a case in a query

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version

    I'll have the data in the table below-
    drop table stud_fact;
    create table stud_fact(stud_NM, LVL_CD,ST_DT_DIM_KEY,OVRNK) as select
    'ABG Sundal','H','20110630','175' from dual union all select
    'ABG Sundal','H','20120630','0' from dual union all select
    'ABG Sundal','Y','20111231','147' from dual union all select
    'ACF Intl','H','20110630','280' from dual union all select
    'ACF Intl','H','20120630','0' from dual union all select
    'ACF Intl','Y','20111231','418' from dual union all select
    'AK Invest','H','20110630','485' from dual union all select
    'ANZ','H','20120630','0' from dual union all select
    'Arbor','H','20110630','12' from dual union all select     
    'Arbor','H','20120630','21' from dual union all select
    'Arbor','Y','20111231','5' from dual ;
    I use the following sql to retrieve the output-

    Select stud_nm,
    (case when ST_DT_DIM_KEY ' 20110101 ', ' 20111231' and LVL_CD = 'Y' then OVRNK)
    on the other case when ST_DT_DIM_KEY ' 20110101 ', ' 20110631' and LVL_CD = 'H' then OVRNK
    ELSE ' 0'
    END
    END YRRK),
    (case when ST_DT_DIM_KEY ' 20120101 ', ' 20120631' and LVL_CD = 'H' then OVRNK)
    ELSE ' 0'
    LYRK END)
    OF stud_fact

    but it gives the output as.
    RPT_BRKR_N YRR
    ---------- ---
    ABG Sundal 175
    ABG Sundal 0
    ABG Sundal 147
    ACF Intl   280
    ACF Intl   0
    ACF Intl   418
    AK Invest  485
    ANZ        0
    Arbor      0
    Arbor      0
    Arbor      0
    I expect the output to be-
    stud_nm          yrrk     lyrk
    ABG Sundal     0     147
    ACF Intl     0     418
    AK Invest     0     485
    ANZ          0     0     
    Arbor          21     5
    select stud_nm,
             max(case when st_dt_dim_key between '20120101' and '20121231' then ovrnk
                                     else '0' end)
                          keep (dense_rank first
                                order by
                                case when st_dt_dim_key between '20120101' and '20121231' then 0
                                     else 1 end,
                                lvl_cd desc) yrrk,
             max(case when st_dt_dim_key between '20110101' and '20111231' then ovrnk
                                     else '0' end)
                          keep (dense_rank first
                                order by
                                case when st_dt_dim_key between '20110101' and '20111231' then 0
                                     else 1 end,
                                lvl_cd desc) lrrk
    from  stud_fact s
    where st_dt_dim_key between '20110101' and '20121231'
    group by stud_nm
    order by stud_nm
      ;
    
    STUD_NM    YRRK LRRK
    ---------- ---- ----
    ABG Sundal 0    147
    ACF Intl   0    418
    AK Invest  0    485
    ANZ        0    0
    Arbor      21   5  
    

    Hope the rank column is NUMBER. You need to make changes accordingly...

Maybe you are looking for

  • iPad is locked up on screen is white cord charger and arrow picture and iTunes symbol

    iPad is locked... The screen is black with a picture of the logo of the charger, arrow and iTunes.  Help

  • Slower treatment after 10.11.2

    After updating to 10.11.2 my new iMac 4K had significantly slower. Now it takes time to show me the icons when I open a large file, and the same thing happens when I open files or applications. Please notify.

  • y at - it a trick to find the initial size of the photos

    I want to find the original size of the pictures that r send e-mail by compressing the photos that I receive in my mail... are compressed into one so how can we recover these photos to the original size...

  • R61i - Bluetooth pairing with SE HBH-DS980

    Hello world I hope that im in the right place for help... got this cool bluetooth headset device and tried to connect with my Thinkpad but I couldn't seem to make it work. I have the latest firmware updates from / of the disc on both devices. Does an

  • Ripple scrambled emulator interface

    Hello world I tried to enter in WebWorks and downloaded the emulator to ripple, but when I start it, I see the blurred, according to my attached image interface. No idea why? I tried to reinstall without success. Is there a dependency/setting I need