Combine two results of the query with rank

Dear all,

I'm an analyst working DB for the first time:

I have two requests:
1)
Select * (select 'CAFNo', 'ActionDate', 'ActionDetail', rank() on rnk (partition by order of 'CAFNo' through 'ActionDate'),
of 'ABC '.
where 'ActionDetail '.
as 'FIU successfully presented and routed to the fulfillment team %')
where rnk = 1

Results in
CAFNo', 'ActionDate1', 'ActionDetail '.

2)
Select * (select rank() on rnk (partition by order of "CAFNo" by "ActionDate"), 'CAFNo', 'ActionDate', 'ActionDetail'
of 'ABC '.
where 'ActionDetail '.
like '% customer ID %')
where rnk = 1

Results in
CAFNo', 'ActionDate2', 'ActionDetail '.
---------------------------------------------------------------------
I would like to combine the results of two as:
No College, Actiondate1, actiondate2, ActionDetail

I tried the full outer join and other options but without success. Help, please
Please share concept to join the two results not the actual query.
with t as (
           select  "CAFNo",
                   "ActionDate",
                   "ActionDetail",
                   case
                     when "ActionDetail" like '%Customer ID%' then 2
                     else 1
                   end weight,
                   rank() over(
                               partition by "CAFNo",
                                             case
                                               when "ActionDetail" like '%Customer ID%' then 2
                                               else 1
                                             end
                               order by "ActionDate"
                              ) rnk
             from  "ABC"
             where "ActionDetail" like '%Customer ID%'
                or "ActionDetail" like 'CRF successfully submitted and routed to Fulfillment Team%'
          )
select  "CAFNo",
        max(
            case weight
              when 1 then "ActionDate"
            end
           ) "ActionDate1",
        max(
            case weight
              when 2 then "ActionDate"
            end
           ) "ActionDate2",
        max(
            case weight
              when 1 then "ActionDetail"
            end
           ) "ActionDetail1",
        max(
            case weight
              when 2 then "ActionDetail"
            end
           ) "ActionDetail2"
  from  t
  where rnk = 1
  group by "CAFNo"
/

SY.

Tags: Database

Similar Questions

  • Is there a way to combine their results of the query in a single function

    I have a bunch of functions that return a query:

    < cffunction = access "getDeals" name = "remote" returntype = "query" >
    < cffunction = access "getDeals2" name = "remote" returntype = "query" >

    is there a way to combine their results of the query in a single function that returns a structure of different results?

    Uh, it is probably more suited to a table - effectively turning it into a list of queries. Then you loop the array and each output.

    I use a similar approach in the creation of the system of the user messages. Most of my functions that are called do their part, then at the end call another function, I called 'messages '. This function takes all what my function sends and adds it to a message board.

    Keeps me out of a long list of messages - because I could call several functions at the same time. If I have just the output of a message of each function, each would crush the other. So, I'd get one message at a time.

    Immediately after that he was released, I will destroy it then the message table so that messages are not kept inside.

    Mikey.

  • Display of the results of the query with the column names unknown

    I use this code to grab the headers of columns in a select * statement. (I never know what table is queried out of 12 000 or more.) I want to make a loop on the column headers, then the query results in a web page table.

    < cfoutput >
    < cfset colHeaderNames = ArrayToList (recordset1.getColumnList ()) / >
    #colHeaderNames #.
    < / cfoutput >

    Is there a similar method or suggestions for the release of the results of the query - now that I know the column headings?

    If I understand correctly, you can do something like the code below.

  • results on the query with filter, but no results when the filter removed

    I was handed the query below and I may be missing something blinding here but if I run it I get no results

    SELECT lipqoh
    OF f41021 a, b f0006
    WHERE b.mcmcu = a.limcu AND
    b.mcstyl = "W";

    If I add the filter a.liitm = 105900 as data below is returned (although the inputs are 0 as expected at the moment, this isn't always the case)

    SELECT lipqoh
    OF f41021 a, b f0006
    WHERE b.mcmcu = a.limcu AND
    b.mcstyl = 'W '.
    a.liitm = 105900;

    the fields for each of the tables mentioned in the motion have the following features

    lipqoh number NULLABLE
    mcmcu Char(12 BYTE) NOT NULLABLE
    mcstyl tank (2 BYTE) NULLABLE
    liitm number NO NULLABLE

    Any guidance would be greatly appreciated

    Thank you for providing feedback. The only difference seems to come from the mcstyl columns.
    The following snipplet perhaps explain how this expression may be true or not true according to the data types.

    select * from dual
    where 'W ' = cast('W' as char(2 byte));
    
    DUMMY
    -----
    X
    
    select *  from dual
    where cast('W ' as varchar2(2 byte)) =  'W';
    
    no rows found
    

    This statement returns all rows?

    SELECT lipqoh
    FROM f41021 a , f0006 b
    WHERE b.mcmcu = a.limcu
    AND   b.mcstyl = 'W '; /* blank added */
    

    I expect so. I still don't understand why oracle treats differently the two queries. However I do not have an adequate control environment. Your version is simply a bit outdated (no longer supported). And I know that some of the type conversion rules had been changed between 9i and 10g.

    Published by: Sven w. on March 30, 2010 15:15

  • Insert the results of the query with constants

    I need to select a table primary keys, then insert them into another table with a status value.

    Select SQL would SELECT APP_ID OF PLAINTIFF WHERE LAST_NAME 'L % '.

    I need all the APP_IDs insert into a table along a status of "in PROGRESS". The table has two columns; ID and the STATE.

    How to combine these operations?

    You can try

    Insert into your_table(ID,STATUS)
     SELECT APP_ID ID,'IN PROGRESS' STATUS FROM APPLICANT WHERE LAST_NAME LIKE 'L%';
    commit;
    
  • HO to get the result of the script with query of 11 g

    Hello

    While doing tasks of refreshment as you need to run some select query. am so lazy to check each application one by one, so I've placed all querys in a script and I ran
    I was fine but it does not show only the result of the query, but it shows no query. Can we get the query and put query via the script out.

    Ex: one.sql
    have the script below the querys

    Select the name of database v$.
    Select count (*) from v$ datafile;
    Select count (*) from dba_db_links;
    Select the owner, db_link dba_db_links;

    can someone help me on this...

    Concerning

    Published by: 889571 on 19 may 2013 14:59
    [oracle@localhost samples]$ cat sample.sql
    set term on echo on
    select name from v$database;
    select count(*) from v$datafile;
    select count(*) from dba_db_links;
    select owner,db_link from dba_db_links;
    [oracle@localhost samples]$ sqlplus user1/user1 @sample.sql
    
    SQL*Plus: Release 11.2.0.2.0 Production on Sun May 19 16:06:20 2013
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> select name from v$database;
    
    NAME
    ---------
    ORCL
    
    SQL> select count(*) from v$datafile;
    
      COUNT(*)
    ----------
             6
    
    SQL> select count(*) from dba_db_links;
    
      COUNT(*)
    ----------
             0
    
    SQL> select owner,db_link from dba_db_links;
    
    no rows selected
    
    SQL> 
    
  • Compare the result of a query with a number and return a message

    Hello
    I have the following query in oracle 9i:

    SELECT COUNT (*)
    OF hourly_files
    WHERE date_received = TO_DATE ((SELECT TO_CHAR (SYSDATE - INTERVAL '1' DAY, 'DDMMYYYY')
    (THE DOUBLE), 'DDMMYYYY');

    This will produce a number of lines required

    I need to compare the number of output with another number hardcoded (threshold) and print an appropriate example message

    If the result of the query above is 18000 and the number of threshold is fixed at 20000, then output a meesage:

    Number of files received less than 2000

    Any help will be very appreciated!

    Thank you.
    SQL> ed
    Wrote file afiedt.buf
    
      1  SELECT CASE WHEN COUNT(*) >5 THEN 'Number is > than 5'
      2              WHEN COUNT(*) <1 THEN 'Its less than 1'
      3  ELSE 'Its in between'
      4  END
      5  FROM emp
      6* WHERE deptno=20
    SQL> /
    
    CASEWHENCOUNT(*)>5
    ------------------
    Its in between
    
    SQL> SELECT COUNT(*) FROM emp
      2  WHERE deptno=10;
    
      COUNT(*)
    ----------
             3
    
  • Determine if the result of the query begins with a number

    I have the results of the query like this

    123PKM
    AAPL
    WB
    9865W
    FC
    QRST

    How can I determine if the result of the query begins with a digit?
    As 123PKM and 9865W do not start with a number.

    But others did not.

    The refind() would make this task very easily. Not tested, but I think that
    It would be the idea.

    #refind('^[0-9]',myQuery.aField,1,false) #.

    ColdFusin documentation in all directions will define completely the
    refind() function capabilities. It will give even some basics
    the syntax of the regular expressions used by this function.

  • Results of the query variant with unused table in the from clause

    Hi all

    I (processing_table2) table specified in the FROM clause in the SQL query , but I have not used any of its value in the SQL statement , but it still affects the results of the query. Please help me out here I'm naïve.

    This is the provided query

    SELECT SUM((CREV.sadc_extd*CSSP.redit_pcnt)/100)

    OF crev revenue_lines,.
    cssp sales_split,
    processing_table2
    WHERE crev.order_num = '7631090072'

    Results of the above query : 344028065018.359



    SELECT

    Sum((CREV.sadc_extd*CSSP.redit_pcnt)/100)

    OF crev revenue_lines,.
    sales_split PCSS

    WHERE crev.order_num = '7631090072'

    Results of the above query : 26463697309.1046


    Someone here suggest me pls!

    924804 wrote:
    Hi all

    I (processing_table2) table specified in the FROM clause in the SQL query , but I have not used any of its value in the SQL statement , but it still affects the results of the query. Please help me out here I'm naïve.

    This is the provided query

    SELECT SUM((CREV.sadc_extd*CSSP.redit_pcnt)/100)

    OF crev revenue_lines,.
    cssp sales_split,
    processing_table2
    WHERE crev.order_num = '7631090072'

    Results of the above query : 344028065018.359

    SELECT

    Sum((CREV.sadc_extd*CSSP.redit_pcnt)/100)

    OF crev revenue_lines,.
    sales_split PCSS

    WHERE crev.order_num = '7631090072'

    Results of the above query : 26463697309.1046

    Someone here suggest me pls!

    CARTESIAN PRODUCT of the changes result set

  • merge a result of one query with another

    Hi all

    I have a question that the result of the query should be considered as 1 column and the result of another

    TABLE 1:

    CREATE THE TEST_QUERY TABLE (EMP_ID, EMP_NAME VARCHAR2 (100), EMP_ROLE VARCHAR2 (100));

    INSERT INTO TEST_QUERY VALUES (1, 'Jack', 'Dev');

    INSERT INTO TEST_QUERY VALUES (2, 'Mike', 'Tester');

    INSERT INTO TEST_QUERY VALUES (3, 'Steve', 'Support').

    TABLE 2:

    CREATE TABLE TEST_QUERY1 (NUMBER OF EMP_ID, EMP_NICK VARCHAR2 (100), EMP_VALUE VARCHAR2 (100));

    INSERT INTO TEST_QUERY1 VALUES (1, 'ROLO', 'GOOD');

    INSERT INTO TEST_QUERY1 VALUES (2, 'POLO', 'BAD');

    INSERT INTO TEST_QUERY1 VALUES (5, 'ZHANG', 'POOR');

    my request of intent:

    SELECT count (p.emp_id), p.emp_id, q.emp_value, q.emp_nick test_query p test_query1 q where p.emp_id = group q.emp_id of p.emp_id, q.emp_value, q.emp_nick;

    Because I need to use more than 100 columns in table TEST_QUERY1, to avoid adding more columns in the group by I thought I can take the result of the column of table 1 separately and the result of the columns in table 2, then combine the two to aid WITH the Clause, but it did not work

    Query I wrote:

    WITH P ACE (SELECT count (T.EMP_ID), T.EMP_ID OF TEST_QUERY T, TEST_QUERY T1 WHERE T.EMP_ID = T1. GROUP BY T.EMP_ID EMP_ID),

    Q AS (SELECT S.EMP_ID, S.EMP_NICK, TEST_QUERY S.EMP_VALUE R, TEST_QUERY1 S WHERE R.EMP_ID = S.EMP_ID)

    SELECT P, Q.* P, Q;

    Please help me...

    You took your idea too far. Yes, it is better to GROUP BY before the JOIN, but you don't need GROUP by your second 'query '.

    Also, you left out the part of the join.

    Assuming that I understand your question, here's something:

    with P as (
      select count(*) emp_id_cnt, emp_id
      from test_query
      group by emp_id
    )
    select P.emp_id_cnt, P.emp_id, Q.emp_nick, Q.emp_value
    from P, test_query1 Q
    where P.emp_id = Q.emp_id;
    
  • Procedure to export the result of the query to an excel or csv

    Hi all

    I have two identical paintings

    EMP_TEST OF THE EMP

    ID ID NAME

    1     SAM                      1        SAM

    2 JOHN 2 ROCK

    3 3 STEVE BRAND

    I need to combine the result under the query and intent to export data to excel using a procedure

    my query is

    Select 'EMP_ID', E1. EMP_ID, AND. EMP_ID from emp E1,

    emp_test AND WHERE E1. EMP_ID = AND. EMP_ID

    UNION

    Select "EMP_NAME", E1. EMP_NAME, AND. Emp E1 EMP_NAME,

    emp_test AND WHERE E1. EMP_ID = AND. EMP_ID

    but I get this error message

    ORA-01790: expression must have same type of corresponding data

    EMP_ID is a number and EMP_NAME is of type varchar.

    I need any idea or suggestion on sub queries.

    (1) I have to combine the result set in a single query.

    (2) I need to write the procedure that will export the result of the query to an excel or csv.

    Thank you.

    As PR has said, there are ways that have already been explained in this forum to write in external files. For your query condition, try this.

    SELECT CASE WHEN (REGEXP_LIKE (T1.ID,'[^ [: alpha:]] "")) THEN 'EMP_ID '.

    ELSE "EMP_NAME' END AS COL_NAME.

    T1.ID,

    T2.ID

    DE)

    SELECT CASE WHEN ID IS NULL THEN NAME ANOTHER TO_CHAR (ID) END AS ID,

    ROW_NUMBER () OVER(ORDER BY RN NULLS FIRST,ID) RN

    DE)

    SELECT ID, NULL,

    NAME,

    RN ID

    FROM EMP

    UNION ALL

    SELECT ID,

    NAME,

    RN NULL

    FROM EMP)) T1.

    (SELECT CASE WHEN ID IS NULL THEN NAME ANOTHER TO_CHAR (ID) END AS ID,)

    ROW_NUMBER () OVER(ORDER BY RN NULLS FIRST,ID) RN

    DE)

    SELECT ID, NULL,

    NAME,

    RN ID

    OF EMP_TEST

    UNION ALL

    SELECT ID,

    NAME,

    RN NULL

    OF EMP_TEST)) T2

    WHERE T1. RN = T2. RN;

    OUTPUT:

    COLUMN-NAME ID ID
    --------  ---------------
    1 1 EMP_ID
    2 2 EMP_ID
    3 3 EMP_ID
    SAM EMP_NAME MARK
    EMP_NAME JOHN JOHN
    EMP_NAME STEVE DARREN

    6 selected lines.

  • Result of the query based on the form of the parameter

    Good morning people. I really couldn't come up with a smart enough subject line, but I'll try and make up the body.

    I currently have a report that accepts parameters on the parameter form. They are extra employees and Number of Copies. The employee ID is stored in the Employee table, but the number of copies is not.

    The output of the report shows all the different addresses and phone numbers, the employee a. lets say, Employee ID 0001 has two addresses - home and office. In the report of my request, he'll give me two records in the repeating group. However, I have another parameter and the ID of the employee who is the number of Copies. In this case, if the number of Copies to be printed is 1, so it isn't a problem. However, if the Number of Copies is entered by the user is 4, I think in this case 4 x 2 = 8 pages of report output (4 with the address of the House) and 4 with the address of the office.

    I know there is a way to do this using a temporary table in AfterPForm and then using the results of the query by joining my request to the temporary table, but I was really hoping to avoid this situation if it can be treated through the query.

    Main request:
    SELECT    e.emp_no,
              e.saln||e.first_name||' '||e.last_name emp_name,
              a.street,
              a.city||' '||a.province||' '||a.postal_code city,
              '('||a.tel_area||') '||a.tel_number telephone
    FROM      employee e, emp_address a
    WHERE     e.emp_no = a.emp_no
    AND       e.emp_no = :P_EMP_NO;
    Any help is appreciated. Thank you!

    Hello

    Since you started a new thread in the forum SQL and PL/SQL {message identifier: = 10470358}, please mark this thread as "Answered" right away.

  • Rewrite the query with joins, and group by

    Hello

    It's an interview question.

    Table names: bookshelf_checkout
    virtual library

    And the join condition between these two tables is title

    We need to rewrite under request without using the join condition and group by clause?

    SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
               FROM bookshelf_checkout bc,bookshelf b
               WHERE bc.title(+)=b.title
               GROUP BY b.title;
    When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.

    Kindly help me on this.

    Thank you
    Suri

    Something like that?

      1  WITH books AS (
      2  SELECT 'title 1' title FROM dual UNION ALL
      3  SELECT 'title 2' FROM dual UNION ALL
      4  SELECT 'title 3' FROM dual ),
      5  bookshelf AS (
      6  SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
      7  SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
      8  SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
      9  SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
     10  UNION
     11  (SELECT b.title, NULL FROM books b
     12  MINUS
     13* SELECT bs.title, NULL FROM bookshelf bs)
    SQL> /
    
    TITLE   MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
    ------- ------------------------------------------------------------
    title 1                                                           14
    title 2                                                           44
    title 3
    

    Lukasz

  • ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    Hello!

    I have a simple object type and a proecdure in which I am trying to use it to insert into another table

    -object

    CREATE ORREPLACETYPEmt_mtg ASOBJECT

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;

    -same structure as the use of sampletbl target table in the cursor query

    create table tbl_MT_MTG

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    -procedure

    CREATE ORREPLACEINTERIORTEST_PROCEDURE1

    AS

    ref_cur sys_refcursor ;

    REFR ref_mtg ;

    BEGIN

    OPEN ref_cur FOR

    Select acol,

    BCOL

    DE sampletbl rownum<10;

    Fetch ref_cur in bulk collectintorefr;

    Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);

    commit;

    CLOSE Ref_cur;

    END;

    /

    When I run this procedure fails with

    ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    ORA-06512: at "TEST_PROCEDURE1", line 10

    ORA-06512: at line 2

    Any help on this please...

    Thanks to an OLD POST below

    so perfect helped me! Thank you

    Tubby

    After 5 years of more :-)

    How to store refcursor in collection How to store refcursor in collection

  • Result of the query in column mode

    Hello

    the results of the query tab presents its results in lines. For the single line results, it is sometimes useful show the result in a column, so that the fields on a line are presented below between them. Is this possible with SQL Developer?

    Best regards

    Joop

    Yes, the right of the mouse in the grid, and then select "Single Record View"

Maybe you are looking for

  • PC Diagnostic tool does not

    Hello world I have a satellite M30, and the 'PC Diagnostic tool' utility does not work (nothing happens when I click on the program). I have windows XP service pack 1. I uninstalled and downloaded a new site of toshiba, but it still does not work. No

  • The question of transfer NFC Contacts?

    I have two new motorcycle x activated each on their own line. When I try to make a copy of personal contacts than with my contacts on the other without, nothing happens after I 'touch screen '. I have the NFC & Android beam activated on both; Bluetoo

  • Net use does not suspend persistent connection Surface RT to NAS.

    Original title: net use is not persistent Hello I want to connect my rt surface to my NAS. I tried with the build in option to explore to connect to this share. I also tried command line net use to this end. In both cases, it works well. In both case

  • Extras in Photoshop CC keep appearing

    For some reason when I opened Photoshop this morning additional guidance around layers keep showing. I tried to put it out under the view and H command. She disappears for a moment, then the next layer I active, it turns back on. I'm not used to work

  • How to install updates for Adobe Master CS5?

    I received a message from Adobe (June 1) that the updates are available for my CS5 software. I then tried to update (several times using different methods, etc.); but never fully succeeded. Please tell me how to do updates (in detail).