To select adjacent records of same amount

Oracle Version = Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

Hi gurus

Yet once again, I need your help, I have the following data samples:

Sample data:

AS WITH a reference

(

SELECT 100 c_id,

TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.

TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.

TN 55

OF the double

UNION ALL

SELECT 100 c_id,

TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.

TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.

55

OF the double

UNION ALL

SELECT 200 c_id,

TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.

TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.

60

OF the double

UNION ALL

SELECT 200 c_id,

TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.

TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.

75

OF the double

UNION ALL

SELECT 200 c_id,

TO_DATE (November 2, 2008 ', 'dd-mm-yyyy') Eff_dt,.

TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.

60

OF the double

)

SELECT * REFERENCE

order by 1, 2;

The query result

C_ID, EFF_DT, TER_DT, TN

100 1 NOVEMBER 06 31 OCTOBER 08 55

100 1 NOVEMBER 08 TO 31 DECEMBER 15 55

200 1ST NOVEMBER 06 31 OCTOBER 08 60

200 1ST NOVEMBER 08 TO 31 DECEMBER 15 75

200 2 NOVEMBER 08 TO 31 DECEMBER 15 60

Required result

100 1 NOVEMBER 06 31 OCTOBER 08 55

100 1 NOVEMBER 08 TO 31 DECEMBER 15 55

I need to select contagious AMT against C_ID,

If you see examples of data, then you can see that the AMT 55 is contagious against C_ID = 100.

If you see the same date, then you can see that the AMT 65 is not contagious against C_ID = 200, there is a record that has AMT = 75.

order by should be EFF_DT. Thanks in advance

Concerning

Shu

Hi, Shu,

979596 wrote:

Hi Frank

Thanks for the reply, but when I added a record more against c_id = 200 then I get a wrong result, see below:

Examples of data

AS WITH a reference
(
SELECT 100 c_id,
TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.
TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.
TN 55
OF the double
UNION ALL
SELECT 100 c_id,
TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.
TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
55
OF the double
UNION ALL


SELECT 200 c_id,
TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.
TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.
60
OF the double
UNION ALL
SELECT 200 c_id,
TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.
TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
75
OF the double
UNION ALL
SELECT 200 c_id,
TO_DATE (November 2, 2008 ', 'dd-mm-yyyy') Eff_dt,.
TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
60 DOUBLE
UNION ALL
SELECT 200 c_id,
TO_DATE (November 3, 2008 ', 'dd-mm-yyyy') Eff_dt,.
TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
60
OF the double
)
SELECT d.
-COUNT (DISTINCT amt) over (PARTITION BY c_id) AS amt_cnt

REFERENCE d
order by 1, 2
;

The query result

100 1 NOVEMBER 06 31 OCTOBER 08 55

100 1 NOVEMBER 08 TO 31 DECEMBER 15 55

200 1ST NOVEMBER 06 31 OCTOBER 08 60

200 1ST NOVEMBER 08 TO 31 DECEMBER 15 75

200 2 NOVEMBER 08 TO 31 DECEMBER 15 60

200 3 NOVEMBER 08 TO 31 DECEMBER 15 60

Result of your request provided without filtering on amt_cnt

100 1 NOVEMBER 06 31 OCTOBER 08-55-1

100 1 NOVEMBER 08 TO 31 DECEMBER 15 55 1

200 1ST NOVEMBER 06 31 OCTOBER 08 60 2

200 1ST NOVEMBER 08 TO 31 DECEMBER 15 75 2

200 2 NOVEMBER 08 TO 31 DECEMBER 15 60 2

200 3 NOVEMBER 08 TO 31 DECEMBER 15 60 2

...

When I run the query I posted earlier, with new data from the sample, I get no output with c_id = 200 lines.

Power required

100 1 NOVEMBER 06 31 OCTOBER 08-55-1

100 1 NOVEMBER 08 TO 31 DECEMBER 15 55 1

200 2 NOVEMBER 08 TO 31 DECEMBER 15 60 2

200 3 NOVEMBER 08 TO 31 DECEMBER 15 60 2

Maybe you want something like this:

WITH got_neighbors AS

(

SELECT c_id, eff_dt, ter_dt, TN

LAG (amt) over (PARTITION BY c_id

ORDER BY eff_dt

) AS prev_amt

Advance (amt) OVER (PARTITION BY c_id

ORDER BY eff_dt

) AS next_amt

REFERENCE

)

SELECT c_id, eff_dt, ter_dt, TN

OF got_neighbors

WHERE the amt IN (prev_amt, next_amt)

ORDER BY c_id, eff_dt

;

But I'm still guessing only to your needs.

Specifically, I guess you want to see only those rows where TN is the same as the previous amt or amt next of the same c_id, where "previous" and "next" means in order of eff_dt.  However, if this is your requirement, so I do not understand why you did not say a word about eff_dt in your explanation, since eff_dt plays an important role in this problem.

Tags: Database

Similar Questions

  • Information retrieval of dead macbook pro drive without purchase mac with the same amount of disc

    I'm completely lost right now and honestly had a really bad time in the Mac store. I love Macs, the staff is usually great, but I ended up leaving enough frustrated after a few experiences of confusion with the sales guy myself.

    So, I entered the mac store with a 2011 13 inch Macbook Pro which has got water damage. It turns out that it was $750 to fix and I decided that I would just get a new one. It was the hardest or disc information you can have, and I've had about 263 on 500 or something used. I want photos and documents to browse and choose what is important.

    Then they assured me that they could extract the information and make a transfer with my computer, but I have to buy a laptop with the same amount of data - so that the Macbook Air for $1,500 instead of $1000 Macbook Air, I was going to learn how to do the transfer. They kept saying it's a case all or nothing-, they cannot choose the data from the hard drive, nor can they give it to me in a way that does not require a complete transfer of the computer and so a computer with a drive for.

    Is it possible that I can do this by a third party? Or download the information from the hard drive on something other than a full computer...?  I honestly don't need, want or have the capability of the computer with the disc like means. I just need a computer for school and would like to stick with the Mac, and the hard drive more small $1000, that's what I can afford right now.

    Thank you and sorry if it came out confused, I'm just really frustrated, I lost all my information to my own stupid mistake and cannot repair.

    p. s.

    Nothing is saved on iCloud and I don't have Time Machine.

    Remove the drive from the computer and install it in an external USB enclosure.

  • Why my iPhone has a capacity lower than my iPad when they have the same amount of storage?

    Why my iPhone has less capacity (storage wise) than my iPad when they both have the same amount of storage?  My pictures takes up to 7.2 GB on my iPhone with only 700 pictures & my iPad takes up to 4.0 GB with more than 1,000?

    Check the settings of your devices to the settings > Photos & camera > iCloud photo library > do you both value library optimized? If NOT, this is your answer. If YES, then the size of the local library is adjusted based how much space you have, if you change or display more than full resolution images on a device, than another, on what device the photos were taken, etc.

  • How to select a record in one table to manipulate data in a database?

    Hello community,

    Using 32-bit Labview 2015.

    I created a user interface that runs a query and retrieves my table from a sql database.

    I want to be able to manage only one record at a time by selecting the record in my table and then manipulate the data according to the needs.

    Whenever the user runs a query, I want as the first record in the table to be selected / highlighted.

    I want an indicator that is currently active.

    Then a click of a button, to be able to scroll the actively selected record.

    Once I have the selected record, I want a way to write a query to edit or delete the record.

    Is attached a photo of my query to select all of my table and connect data in my table (results).

    Attached a photo of my painting showing the timeline of my sql database.

    What is the best way to go on a record selection in a table and the modification of data with a query?

    Any help would be greatly appreciated.

    Thank you

    I guess that's not a table, but multi-column listbox.

    Right click, select--> highlight whole line selection Mode

    The value of the multicolumn listbox is the row index - you can write a local variable to highlight the line, the event structure to handle the user clicking on, etc.

    If you enable the property editable ListBox cells, you can allow users to edit the items of the listbox.

    If you want to get the data in row, you hint REF table and work with the array of strings in row - convert it to cluster, etc..

    I don't know, what type of data, it is, how you structure the database looks like, I don't even know if you use the wrapper to work with the database, I can't write queries for you.

    Something like Update Tablica Set Serial = '5' where ID = '22';

  • record selector don't work for the specific selection of records

    Hello

    I have a problem with the record selector in the spotlight.

    I want to select specific record, but when I select the control in the record are not in the selected record tab!

    the dataservice.json and endecaBrowserService.json files are correctly set up I think. I compare it with the app to Discover, but I do not want would be the question! not that the dynamic selection of records are working properly

    endecaBrowserService.json

    {

    "host': 'W177."

    "port": "15101."

    "recSpecProp": "Product_SKU",

    "recAggregationKey": "Endeca_Rollup_Id",

    "recFilter",:

    "recImgUrlProp": "URL_Thumbnail1",

    'recDisplayProps': ['brand', 'Category_EN', 'Product_SKU'],

    "textSearchKey": "interface_EN",

    'textSearchMatchMode': 'ALLPARTIAL '.

    }

    DataService. JSON

    {

    "jcr:primaryType': ' short: unstructured."

    "host': 'W177."

    "port": "15101."

    "recordSpecName": "Product_SKU",

    "aggregationKey": "Endeca_Rollup_Id",

    «recordFilter ": «,»

    'wildcardSearchEnabled': false,

    "recordNameField": "product_name_en",

    "fields": {"Brand": "', 'Category_EN': '',' Product_SKU'": ""}

    }

    any idea

    Thank you

    What is the record specification for records that fail?  For example, I found that the editor will fail if the record ID have spaces. That is to say 'Id1 Id2'.  Our resolution after conferring with support is to add an underscore 'Id1_Id2 '.

  • Best way to horizontally align a row of images with the same amount of filling

    Basically, I want to line up a row of images horizonally each with the same amount of space between each. What would be the best way to go about this? should I put in a div?

    I want to watch how images would be aligned in a clothing site. Thus, for example, like this - http://shop.thehundreds.com/c-439-tees.aspx

    Thank you

    Hi Hannah (?),

    You can try one of the models of Nancy O. from here: http://alt-web.com/TEMPLATES/CSS-Semi-liq-photo-sheet.shtml.

    Hans-Günter

  • Multiple selection of records in table advanced to update in the Search Page.

    Hi all

    I write the code below, to select multiple records in table advanced for the update after clicking on the button update in the Search Page.
    I write this code in Processform request, but I got the exception when I run the code below.


    If (PageContext.GetParameter ("UpdateOnSeaBtn")! = null)
    {
    Am = (XxSupppacklistAMImpl) pageContext.getApplicationModule (webBean) XxSupppacklistAMImpl;
    am.saveRollback ();
    OAViewObjectImpl upDtVO = (OAViewObjectImpl) am.findViewObject ("PackingListSeaVO");
    PackingListSeaVORowImpl line;

    HashMap vParm = new HashMap();

    Row [] rows = upDtVO.getFilteredRows ("SingleSelection", "Y");
    int fetCount = upDtVO.getRowCount ();
    System.out.println ("Teh recovered rowcount is:," + fetCount);

    RowSetIterator multiIter;
    multiIter = upDtVO.createRowSetIterator ("multiIter");
    multiIter.setRangeStart (0);
    multiIter.setRangeSize (fetCount);


    for (int i = 0; i < fetCount; i ++)
    {
    Row = (PackingListSeaVORowImpl) multiIter.getRowAtRangeIndex (i);
    If (Row.GetAttribute ("SingleSelection")! = null)
    {
    If (Row.GetAttribute ("ItemNumber")! = null)
    {
    Object vitemNum = row.getAttribute ("ItemNumber");
    System.out.println ("The selected element Num is:," + vitemNum);
    vParm.put ("ItemNumber", vitemNum);

    pageContext.setForwardURL ("OA.jsp?page=/xxfls/oracle/apps/po/packlist/webui/XxSuppalistcrealistPG", / / here, I got the exception below)
    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    vParm,
    false, / / RetainAM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }
    }
    }

    multiIter.closeRowSetIterator ();

    }
    }
    }

    could you, please, can someone help on this.


    I got below exception to the side server when it is run the code above.
    Error (125,48): method setForwardURL (java.lang.String, null, null, byte, java.util.HashMap, boolean, java.lang.String, byte) is not not in the interface oracle.apps.fnd.framework.webui.OAPageContext

    Kind regards

    Hello

    832859 wrote:

    for (int i = 0; i)<>
    {
    Row = (PackingListSeaVORowImpl) multiIter.getRowAtRangeIndex (i);
    If (Row.GetAttribute ("SingleSelection")! = null)
    {
    If (Row.GetAttribute ("ItemNumber")! = null)
    {
    Object vitemNum = row.getAttribute ("ItemNumber");
    System.out.println ("The selected element Num is:," + vitemNum);
    vParm.put ("ItemNumber", vitemNum);

    > pageContext.setForwardURL"OA.jsp.page=/xxfls/oracle/apps/po/packlist/webui/XxSuppalistcrealistPG",//here I got below exception

    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    vParm,
    false, / / RetainAM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }
    }
    }

    -Here is you call pageContext.setForwardURL loop.
    >

    I got below exception to the side server when it is run the code above.
    Error (125,48): method setForwardURL (java.lang.String, null, null, byte, java.util.HashMap, boolean, java.lang.String, byte) is not not in the interface oracle.apps.fnd.framework.webui.OAPageContext

    -check 5th param should nt be vParm if it is null

    Finally... After the for loop ends call... y bcz assume this page grouped 10 rows can he navigate both on the next page...:

    pageContext.setForwardURL ("OA.jsp?page=/xxfls/oracle/apps/po/packlist/webui/XxSuppalistcrealistPG",
    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    NULL,
    false, / / RetainAM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }

    Concerning
    Meher Irk

    Published by: Meher Irk on March 31, 2011 19:54

  • By selecting certain records by using the check box

    Hello

    I have a similar problem mentioned in this thread Re: select specific records using the checkbox I got if I have only one primary key value in the work table. I don't know how to handle it when I have several primary keys of the table I want to use for filtering?

    Thank you.

    Hello

    You can use rowid
    First report

    SELECT APEX_ITEM.CHECKBOX(1,e.rowid) chk,
    e.*
    FROM emp e
    

    Use even submit after processes.
    And target page report

    SELECT e.*
    FROM emp e
    WHERE EXISTS(
    SELECT 1
    FROM apex_collections c
    WHERE c.collection_name = 'P46COL'
    AND c.c001 = e.rowid)
    

    Kind regards
    Jari

    Published by: jarola on October 14, 2010 10:50

  • Selection of records over 90 days

    Can someone tell me a way to select all records that are older than 90 days? I have a field named PostedDate which is the date that the record was created. I use MS Access.

    Thank you!

    Copy the following code:

    Select * from employee where startdate<>

    This means:

    Select * from employee where startdate<>

  • Selection of records in the same table problem

    Hi all

    I have the following table
    with emp as (
               select '11' A,'aaa' B, '40' C from dual union all
               select '11','bbb', '40' from dual union all
               select '33','ccc', '30' from dual union all
               select '44','ddd', '20' from dual union all
               select '11','eee', '10' from dual
              )
    My results should be
    A           B        C
     
    11        aaa      40
    11        bbb     40      
    11        eee     10
    Basically the requirement is select different combination of values in the column 'B' need to know what is the value of 'A' (it must be the same for all records of three)


    Hope in this sense.


    See you soon

    Sexy

    an attempt to rephrase:

    you want all the files "aaa", "bbb" and "EEA" where, for each set of column A, where they exist.

    that is, if games to have only "aaa" and "bbb" but not "eee" in column B, then you don't want to retrieve this record?

    Try this:

    SQL> with emp as (
      2  select '11' A,'aaa' B, '40' C from dual union all
      3  select '11','bbb', '40' from dual union all
      4  select '33','ccc', '30' from dual union all
      5  select '44','ddd', '20' from dual union all
      6  select '11','kkk', '20' from dual union all
      7  select '10','eee', '20' from dual union all
      8  select '11','eee', '10' from dual
      9  )
     10  select a, b, c
     11   from (select emp.*, count(*) over (partition by a) cnt
     12    from emp
     13   where b in ('aaa','bbb','eee'))
     14   where cnt = 3
     15  /
    
    A                                B                                C
    -------------------------------- -------------------------------- --------------------------------
    11                               eee                              10
    11                               aaa                              40
    11                               bbb                              40
    
    3 rows selected.
    

    Published by: WhiteHat June 30, 2011 11:04

  • Query to select other records and then the same in 2 tables

    Dear all,

    My database is 10 gr 2 and OS is Linux.
    I have 2 tables with the same fields and almost the same data. There are just a few different lines in table 1 and table 2 that do not match each other.

    I need to select these non-matching rows in both tables in a single request.

    Kindly help on that.

    Best regards, Imran

    You have at LEAST two ways!

    (SELECT * FROM table_A
    minus
    SELECT * FROM table_B)
    union all
    (SELECT * FROM table_B
    minus
    SELECT * FROM table_A)
    /
    

    For example:

    SQL> create table table_a (col_1 number,  col_2 varchar2(5));
    
    Table created.
    
    SQL> create table table_b (col_1 number,  col_2 varchar2(5));
    
    Table created.
    
    SQL> insert into table_a values (1,'A');
    
    1 row created.
    
    SQL> insert into table_a values (2,'B');
    
    1 row created.
    
    SQL> insert into table_b values (1,'X');
    
    1 row created.
    
    SQL> insert into table_b values (2,'Z');
    
    1 row created.
    
    SQL> insert into table_a values (3,'C');
    
    1 row created.
    
    SQL> insert into table_b values (3,'C');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL>
    SQL> select * from table_a minus select * from table_b
      2  union all
      3  select * from table_b minus select * from table_a
      4  /
    
         COL_1 COL_2
    ---------- -----
             1 X
             2 Z
    
    SQL> (select * from table_a minus select * from table_b)
      2  union all
      3  (select * from table_b minus select * from table_a)
      4  /
    
         COL_1 COL_2
    ---------- -----
             1 A
             2 B
             1 X
             2 Z
    
    SQL>
    

    Hemant K Collette

  • Bill standard and a note of credit with the same amount

    Hello
    I have a standard AP invoice with an amount of €100 and the note of credit-€100.

    The standard invoice and credit rating have the same supplier and distribution and status are validated and recorded is Yes.

    How do I match this credit note to this invoice?

    If I try to create a payment with this invoice and credit note, I get an error because I can't make a payment to zero.

    I do so with a suspense account? How can I do?

    Thanks in advance!

    Hello.

    Enter a zero payment amount and select the two documents.

    Octavio

  • How can I get the data view to display the same amount of time I save?

    I use the Sound and Vibration Measurement Suite.  In the data view, I display a graph of time, the power spectrum, the Color Map and the waterfall.  I am also showing strength in numbers group for several bands and doing cutting-edge research.  I record 100 ms of the transient wave.  In the data view, why the temporal plots show several seconds of data?  What determines how much time will appear in the data view?  More important, the power spectrum reflects the power for the entire of several seconds of data displayed?  Same question for power in the values of band and cutting-edge research.  I want to just this data displayed for 100 ms of the wave that I record.  So, how can I get the data displayed (waveforms) and power numbers come only 100 ms of the recorded wave?

    Finally, what is the best way to make account concisely the recorded data?  By slide numbers on the Documentation tab is not concise, because it comes with graphics, etc..  I tried save as ASCII/LVM, but I get a bunch of stuff intermiated I don't care.  Help?

    Hi TimRsandiego,

    SignalExpress is programmed to display graphs with default scales based on the type of action, it's reading. These scales and settings can be changed by right-clicking on the graph, and then select Properties.

    If you are interested to learn more about how to use SignalExpress, I would recommend checking out some demonstrations/tutorials on NI.com. You can find some of these demos at the following location:

    Let me know if you have any other questions.

    Kind regards

  • SELECT generate records

    Hello guys, I have some difficulty in writing of a SELECT statement. I opened a discussion on a subject like this one a few weeks ago.

    But, since I closed it, I reopen a new. Imagine the following scenario. I have a table with the documents, another with an attachment and a junction between these two table. Documents and attachments can have different version. There is a technique used for the foreign key id and the id of commercial real is the combination between document_id and version (even in version and attachment whith attachment_id).

    It is a simplified version of my reality... But let's concentrate on this simple scenario.

    -- The technical id is used for foreign keys. 
    -- [document_id is a business key and the combination of document_id version is unique]
    CREATE TABLE documents 
    (
      technical_id NUMBER(10), 
      document_id number(10),
      version number(10),
      title varchar2(100)
    );
    
    
    CREATE TABLE attachments
    (
      technical_id number(10), -- primay key 
      attachment_id number(10),  -- concat of attachment_id and version is unique!
      version number(10),
      language varchar2(100),
      title varchar2(100)
    );
    
    
    CREATE TABLE doc_attachments
    (
      document_id number(10),
      attachment_id number(10)
    );
    

    Now, imagine the following inserts.

    INSERT INTO documents(technical_id, document_id, version, title) VALUES(1, 1, 1, 'document 1 (version 1)');
    INSERT INTO documents(technical_id, document_id, version, title) VALUES(2, 1, 2, 'document 1 (version 2)');
    INSERT INTO documents(technical_id, document_id, version, title) VALUES(3, 1, 3, 'document 1 (version 3)');
    
    
    INSERT INTO attachments(technical_id, attachment_id, version, language, title) VALUES(99, 10, 1, 'fr', 'attachment 10 (version 1)');
    INSERT INTO attachments(technical_id, attachment_id, version, language, title) VALUES(98, 10, 1, 'en', 'attachment 10 (version 2)');
    INSERT INTO attachments(technical_id, attachment_id, version, language, title) VALUES(97, 10, 2, 'fr', 'attachment 10 (version 3)');
    
    
    INSERT INTO doc_attachments(document_id, attachment_id) VALUES(1, 99);
    INSERT INTO doc_attachments(document_id, attachment_id) VALUES(1, 98);
    
    
    INSERT INTO doc_attachments(document_id, attachment_id) VALUES(3, 97);
    

    In this scenario,.

    -J' have version 3 of the same document.

    -Two different attachments; one of them has two version.

    -3 links between documents and attachments.

    If you pay attention, you will notice that I have no connection between the attachment and the second version of the document. And also, I have different languages for the same attachment. In this scenario, I want to the next exit. The list of all versions of a document with their attachments (all languages) and "gaps" with attachments previous.

    The logic is a bit tricky to understand the output. Basically, for each document, I want to see all the 'last home"received for this folder. Later we hear the fixation with the largest number of version for the same id of attachment.

    doc_tech_id doc_version attac_tech_id attachment_version language
    ----------- ----------- ------------- ------------------ -------- 
             1            1            99                  1       fr -- the first and second insert are generating these two first output records.
             1            1            98                  1       en 
    
    
             2            2            99                  1       fr -- since I did not have any link between the second version of the doc and the attachment, 
             2            2            98                  1       en -- I should have exactly the same as the previous version. So I duplicate records.
             
             3            3            97                  2       fr -- I have a link in the join table between document in version 3 and the second version of the attachment.
             3            3            98                  1       en                     
    

    It is a scenario... I wonder if this is doable in a single query? Can someone help me?

    Thank you

    with

    documents such as

    (select 1 technical_id, 1 document_id, version 1, title "document 1 (version 1)" of all the double union)

    Select 2,1,2, "document 1 (version 2)" dual Union all

    Select 3,1,3, "document 1 (version 3)" of the double

    ),

    As spare part

    (select 99 technical_id, 10 attachment_id, 1 version, language 'fr', "attachment 10 (version 1)" title of all the double union)

    Select 98,10,1, 'FR', "attachment 10 (version 2)" dual Union all

    Select 97,10,2, 'fr', "attachment 10 (version 3)" of the double

    ),

    doc_attachments as

    (select 1 document_id, 99 attachment_id union double all the)

    Select 1.98 Union double all the

    Select double 3.97

    )

    Select the language, attac_tech_id, doc_tech_id, attac_version, doc_version

    from (select doc.technical_id, doc_tech_id,

    doc.version doc_version,

    ATTS.technical_id attac_tech_id,

    ATTS.version attac_version,

    ATTS. Language,

    ROW_NUMBER() over (partition doc.technical_id, atts.language, doc.version

    order by case when doc.version = 3 then atts.version to another atts.technical_id end desc

    ) rn

    document No.

    left outer join

    doc_attachments x partition by (x.attachment_id)

    On x.document_id = doc.technical_id

    inner join

    Spare atts

    On x.attachment_id = atts.technical_id

    )

    where rn = 1

    DOC_TECH_ID DOC_VERSION ATTAC_TECH_ID ATTAC_VERSION LANGUAGE
    1 1 98 1 en
    1 1 99 1 en
    2 2 98 1 en
    2 2 99 1 en
    3 3 98 1 en
    3 3 97 2 en

    the order by clause appears to produce the result you expect, but I can't explain why it should be applied

    Concerning

    Etbin

  • Re: Error on select multiple records

    I need the script below to select a single record by person_id. But when I run it, I have several recordings by same person_id you I used separate in the Charly.

    As you can see below from the result of the query, the person_ids (21934 and 20102) appear twice.

    What I want is only one record a.person_id.

    Any guidance?



    select a.person_id, c.org_name, a.person_type, c.org_code, a.first_name, a.last_name, d.position_title, b.email_address
    from person a, person_emails b, organization c, position_titles d, positions e
    where a.person_id = b.person_id and a.employee_status = 'A' and a.organization_code = c.org_code and a.person_type = 'AMER HIRE' and a.organization_code = e.org_code  and d.position_title_number = e.position_title_number
    order by c.org_name
    ;
    20102 AFRICA Benin AMER HIRE 351801 Robert Tallman EXPERT r
    21934 AFRICA Benin AMER RENTAL 351801 Keith Howard COUNTRY DIRECTOR
    16440 AFRICA Benin AMER HIRE 351801 Jen Norinee EXPERT [email protected]
    20102 AFRICA Benin AMER HIRE 351801 Robert Tallman APCD/RURAL DEVELOPMENT rfrie
    21934 AFRICA Benin AMER RENTAL 351801 John Doe APCD and RURAL DEVELOPMENT
    21934 AFRICA Benin AMER RENTAL 351801 John Doe APCD/PROGRAMMING & TRAINING
    21934 AFRICA Benin AMER RENTAL 351801 John Doe k EXPERT

    You can try this and simply choose the title column that works for you, but for the first or the last title, you will need to fill in the correct sort order for this question:

     SELECT a.person_id
          , c.org_name
          , a.person_type
          , c.org_code
          , a.first_name
          , a.last_name
          , max(d.position_title) max_title
          , min(d.position_title) min_title
          , max(d.position_title)
              keep (dense_rank first order by some_column) first_title
          , max(d.position_title)
              keep (dense_rank last order by some_column) last_title
          , b.email_address
       FROM person a
          , person_emails b
          , organization c
          , position_titles d
          , positions e
      WHERE a.person_id             = b.person_id
        AND a.employee_status       = 'A'
        AND a.organization_code     = c.org_code
        AND a.person_type           = 'AMER HIRE'
        AND a.organization_code     = e.org_code
        AND d.position_title_number = e.position_title_number
      GROUP BY a.person_id
          , c.org_name
          , a.person_type
          , c.org_code
          , a.first_name
          , a.last_name
          , b.email_address
      ORDER BY c.org_name ;
    

    Moreover, in the future try formatting your code is readable with out having to scroll from left to right so.

    Published by: Sentinel on June 4, 2013 13:36

Maybe you are looking for

  • C4600: C4600 with Windows 7

    Bought this C4600 all-in-1 used.  Can be installed on a computer of Windows7.  Get error messages when I click on install.

  • G50 70 swap HDD SSD

    Hi all I have my GG50-70, and I wish to Exchange my HARD for one SSD drive. the laptop is new, so nothing to lose about the data. How to do that with ouy recovery disk or usb stick 16gig. ? I tried to make a backup for OneKey Recovery, but it would b

  • Cannot start the Lenovo on Flex 2 15 recovery media

    So I had a recovery USB bought at LenovoRecovery, however, when I try to start it happens to (it's in German so I will translate it to English) (1) auto repair (2) diagnose your PC... (he diagnoses for 2 minutes) Then opens to the top of the screen t

  • 4500 envy: Envy 4500 not WiFi connection with numere end

    (Same problem with my other laptop running Windows 7) through Wifi or with a USB cable (drivers custom ' settle) Installed with disc or by download, same problem Can not install printer on laptop computers.  Get to the final stage, the last time I di

  • User accounts.

    I got several offices section of our local dump e-waste. All have windows xp installed with one administrator account. Password protected, of course. In most cases I can not reinstall o/s of my drive, or console access recovery due to the lack of per