Find close matched record

I have data in the report_date column and dates are met like this:

report_date
01/01/1990
01/03/1990
01/04/2000
12/05/2000
01/01/2010
01/02/2010

Now I want to select a date in the table which is < = date provided by the user but the query must return only the single record. For example, if the user provides 01/01/1997 query should return 01/03/1990, which is < = 01/01/1997 and closer to 01/01/1997.

If I use WHERE the report_date < = 01/01/1997, then the query returns two records. Y at - it a function or a way to find the closest record matching? Similarly, if the user provides on 01/12/1988 and because there is no available record who has report_date < = 1988-12-01, then it must return more closest date of 01/01/1990.

Published by: skas on sept 17, 2012 16:39


SELECT MIN (RD) AS REPORT_DATE OF
(SELECT MAX (REPORT_DATE) AS RD FROM MY_TABLE
<=>
UNION ALL
SELECT MIN (REPORT_DATE) FROM MY_TABLE
WHERE REPORT_DATE > USER_GIVEN_DATE);

Tags: Oracle Development

Similar Questions

  • Find the matching record better

    create table data(item_no int,item_size varchar2(10),color varchar2(10));
    
    insert into data values (1,null,null);
    
    insert into data values (1,'small',null);
    
    insert into data values (1,null,'pink');
    
    insert into data values (1,'large','red');
    
    create table filters(item_no int,item_size varchar2(10),color varchar2(10),comments varchar2(100));
    
    insert into filters values (1,null,null,'all sizes and colors');
    
    insert into filters values (1,'small',null,'small comment');
    
    insert into filters values (1,null,'pink','love pink');
    
    insert into filters values (1,'large','red','large red comment');
    
    select
    d.item_no,d.item_size,d.color,f.comments
    from data d,filters f
    where d.item_no=f.item_no(+)
    and d.item_size = f.item_size(+)
    and d.color = f.color(+);
    
    

    How would I go about matching records in the data table with the best matching filter table record? Best way where the majority of the attributes match (item_no, item_size and color). I thought a simple outer join would, but it does not quite what I need.

    What Miss me? Thank you

    Hello

    Thanks for posting the sample data.

    Don't forget to post the exact results you want from these data.

    One thing you can do is a Top - N query, like this:

    WITH got_r_num AS

    (

    SELECT d.item_no, d.item_size, d.color, f.comments - or other

    ROW_NUMBER () (PARTITION BY d.ROWID - OR primary key,

    IN CASE of ORDERS WHEN d.item_no = f.item_no THEN 1 END ELSE 0

    + CASE WHEN d.item_size THEN 1 END ELSE f.item_size = 0

    + CASE WHEN d.color THEN 1 END ELSE f.color = 0

    --+... If you have other attributes

    / / DESC

    ) AS r_num

    DATA d

    CROSS JOIN filters f

    )

    SELECT item_no, item_size, color, comments

    OF got_r_num

    WHERE r_num = 1

    ;

    I would like a unique identifier to each table, and I had want to display in the results.

    Remember, in SQL if x or y is NULL then

    x = y

    won't be TRUE.  If you want NULL in two tables to match anything in the other table, then the same general approach will work, but it is messier.

    What results do you want to tie (i.e. for a given line in d, 2 or several lines of f have exactly the same number of corresponding attributes)?

    If this number is 0?

  • Loop Finder crash after upgrading to El Capitan.  'Finder close unexpectedly when you use the plug-in finder' - the message really is in Norwegian, so it may be different for the English operating system.

    'Finder close unexpectedly when you use the plug-in finder' - the message really is in Norwegian, so it may be different for the English.  The e is a compatibility issue with dropbox or Google drive in El Capitan?  Those are the plug-ins only that I could find.  Thank you very much.

    Please launch the Console application in one of the following ways:

    ☞ Enter the first letters of his name in a Spotlight search. Select from the results (it should be at the top).

    ☞ In the Finder, select go utilities ▹ of menu bar or press the combination of keys shift-command-U. The application is in the folder that opens.

    ☞ Open LaunchPad and start typing the name.

    Step 1

    For this step, the title of the Console window should be all Messages. If it isn't, select

    SYSTEM LOG QUERIES ▹ all Messages

    in the list of logs on the left. If you don't see this list, select

    List of newspapers seen ▹ display

    in the menu at the top of the screen bar.

    In the upper right corner of the Console window, there is a search box to filter. Enter the name of the application crashed or process. For example, if Safari has crashed, you would enter "Safari" (without the quotes).

    Each message in the journal begins with the date and time when it was entered. Select the messages since the time of the last fall, as appropriate. Copy to the Clipboard by pressing Control-C key combination. Paste into a reply to this message by pressing command + V.

    The journal contains a large amount of information, almost everything that is not relevant to solve a particular problem. When you post a journal excerpt, be selective. A few dozen lines are almost always more than enough.

    Please don't dump blindly thousands of lines in the journal in this discussion.

    Please do not post screenshots of log messages - text poster.

    Some private information, such as your name, may appear in the log. Anonymize before posting.

    Step 2

    In the Console window, clear the search box, and then select

    DIAGNOSIS AND diagnostic USE information reports ▹ user

    (not diagnose them and use Messages) in the list of logs on the left. There is a disclosure triangle to the left of the list item. If the triangle is pointing to the right, click it so that it points downwards. You will see a list of reports of incidents. The name of each report begins with the name of the process and ends with ".crash". Select the most recent report on the process in question. The content of the report is displayed at right. Allows you to copy and paste to validate all of the content, text, not a screenshot.

    I know that the report is long, perhaps several hundred lines. Please report all this anyway. If the report is only a few lines, make sure that you have disabled the search box.

    If you don't see any report, but you know, he had an accident, you have chosen diagnostic and using the list of Log Messages. INFORMATION on the USE of DIAGNOSTIC AND choose instead.

    In the interest of privacy, I suggest that, before posting, you change the UUID ' anonymous, ' a long string of letters, numbers and dashes in the header of the report, if it is present (it cannot be). "

    Please do not post other types of diagnostic report - they are very long and rarely useful.

    When you post the journal excerpt or the accident report, you might see an error message on the web page: "you have included content in your post that is not allowed", or "the message contains invalid characters." It's a bug in the forum software. Thanks for posting the text on Pastebin, then post here a link to the page you created.

    If you have an account on Pastebin, please do not select private in exposure menu to paste on the page, because no one else that you will be able to see it.

  • What is happening with the DNS requests that cannot not find a matched host (A) RR in the zone are sent to WINS servers, but there is no WINS server installation?

    What is happening with the DNS requests that cannot not find a matched host (A) RR in the zone are sent to WINS servers, but there is no WINS server installation?

    Hello

    Please repost these questions in the Technet Forums

    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

    See you soon.

  • Cannot find a service record for vCenter service with the host name "IP address"

    After upgrading to vCenter native 5.5 to vSphere Client device everything works, but not all orders for PowerCLI.

    After a command gives me error under VMware vSphere PowerCLI 6.0 Release 1

    Get-TagCategory: 13.07.2015 16:50:48 Get-TagCategory could not find a service record for vCenter service with host name 10.x.x.x

    In Zeile:2 Zeichen:1

    + Get-TagCategory

    + ~~~~~~~~~~~~~~~

    + CategoryInfo: ObjectNotFound: (:)) [Get-TagCategory], VimException)

    + FullyQualifiedErrorId: ViCore_InventoryServiceProxy_GetInventoryServiceInfo_NoVcRegistration, VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTagCategory

    does anyone have a solution or an idea for this problem?

    Best

    Marco

    I have exactly the same problem. Are there solutions yet?

    Best regards

    René

    Found the solution in the database (2127028).

  • Find a UNIQUE RECORD on both sides

    Hi, I want to find a unique record that is either A or B who wants to tell A NOT IN B & B NOT in one, here is the sample data

    A side
    -----------
    
    A_SUB_NUM        B_SUB_NUM        START_DATE_TIME         SIDE
    88912345        88912345           20120625000031         A
    77777733        77777733           20120625001608         A
    77777733        77777733           20120625000000         A
    
    
    B side
    -----------
    
    A_SUB_NUM     B_SUB_NUM        START_DATE_TIME    SIDE
    88912345      88912345         20120625000022      B
    88912345      88912345         20120625000028      B
    88912345      88912345         20120625000031      B
    77777733      77777733         20120625001607      B
    IF the START_DATE_TIME differ in 1 second, they are considered the same record, example: 77777733, 77777733, 20120625001608 in one hand is the same as 77777733, 77777733, 20120625001607 B side

    Here is my code, however it didtn give me the expected result that 88912345 have not been filter :(

    (
    SELECT  
    START_DATE_TIME
    ,A_SUB_NUM
    ,B_SUB_NUM
    ,SIDE
    FROM TEST_A t2
    WHERE (A_SUB_NUM, B_SUB_NUM ) NOT IN 
    (SELECT A_SUB_NUM, B_SUB_NUM FROM TEST_B
    where (
    start_date_time > to_char(to_date(t2.START_DATE_TIME,'yyyyMMddhh24miss')-60/86400,'yyyymmddhh24miss')
    and start_date_time < to_char(to_date(t2.START_DATE_TIME,'yyyyMMddhh24miss')+60/86400,'yyyymmddhh24miss')
    )
    )
    )
    
    UNION ALL
    
    (
    SELECT 
    START_DATE_TIME
    ,A_SUB_NUM
    ,B_SUB_NUM
    ,SIDE
    FROM TEST_B t1
    WHERE (A_SUB_NUM, B_SUB_NUM) NOT IN 
    (SELECT A_SUB_NUM, B_SUB_NUM  FROM TEST_A
    where (
    start_date_time > to_char(to_date(t1.START_DATE_TIME,'yyyyMMddhh24miss')-60/86400,'yyyymmddhh24miss')
    AND start_date_time < to_char(to_date(t1.START_DATE_TIME,'yyyyMMddhh24miss')+60/86400,'yyyymmddhh24miss')
    )
    )
    )
    
    This is the result from the query
    
    START_DATE_TIME     A_SUB_NUM     B_SUB_NUM     SIDE
    20120625000000     77777733         77777733       A
    
    
    Expected result should be
    START_DATE_TIME     A_SUB_NUM     B_SUB_NUM     SIDE
    20120625000000     77777733         77777733       A
    20120625000022     88912345         88912345       B
    20120625000028     88912345         88912345       B
    Here is the data dictionary
    CREATE TABLE TEST_A
    (A_SUB_NUM VARCHAR2(50),
     B_SUB_NUM VARCHAR2(50),
     START_DATE_TIME VARCHAR(50),
     SIDE VARCHAR2(2)
     );
    
    CREATE TABLE TEST_B
    (A_SUB_NUM VARCHAR2(50),
     B_SUB_NUM VARCHAR2(50),
     START_DATE_TIME VARCHAR(50),
     SIDE VARCHAR2(2)
     );
    
    INSERT INTO TEST_B
    VALUES ('88912345'    ,  '88912345'     ,    '20120625000022', 'B');
    INSERT INTO TEST_B
    VALUES ('88912345'    ,  '88912345'     ,    '20120625000028' , 'B');
    INSERT INTO TEST_B
    VALUES ('88912345'    ,  '88912345'     ,    '20120625000031', 'B');
    INSERT INTO TEST_B
    VALUES ('77777733'    ,  '77777733'     ,    '20120625001607', 'B');
    
    
    INSERT INTO TEST_A
    VALUES ('88912345'    ,  '88912345'     ,    20120625000031, 'A');
    INSERT INTO TEST_B
    VALUES ('77777733',  '77777733',    20120625000000, 'A');
    INSERT INTO TEST_B
    VALUES ('77777733'    ,  '77777733'     ,    20120625001608, 'A');
    Appreciate your help :)

    Hello

    First of all, I want to note that there is a typing error in the last one you gave instructions insert. Instead of INSERT INTO TEST_B
    VALUES ('77777733', '77777733', 20120625000000, ' A'), you probably want to post INSERT INTO TEST_A
    VALUES ('77777733', '77777733', 20120625000000, ' A') and also instead of INSERT INTO TEST_B
    VALUES ('77777733', '77777733', 20120625001608, ' A'), you probably want to post INSERT INTO TEST_A
    VALUES ('77777733', '77777733', 20120625001608, ' A').

    Here is a solution to your problem:

    select * from test_a;
    
    A_SUB_NUM                                          B_SUB_NUM                                          START_DATE_TIME                                    SIDE
    -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----
    88912345                                           88912345                                           20120625000031                                     A
    77777733                                           77777733                                           20120625000000                                     A
    77777733                                           77777733                                           20120625001608                                     A    
    
    select * from test_b;
    
    A_SUB_NUM                                          B_SUB_NUM                                          START_DATE_TIME                                    SIDE
    -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----
    88912345                                           88912345                                           20120625000022                                     B
    88912345                                           88912345                                           20120625000028                                     B
    88912345                                           88912345                                           20120625000031                                     B
    77777733                                           77777733                                           20120625001607                                     B    
    
    select *
    from test_a
    where   not exists (select *
                      from test_b
                      where abs(to_number(test_b.start_date_time) -
                                to_number(test_a.start_date_time)
                                ) <= 1
                        )
    union
     select *
    from test_b
    where   not exists (select *
                      from test_a
                      where abs(to_number(test_a.start_date_time) -
                                to_number(test_b.start_date_time)
                                ) <= 1
                        ) ;
    
    A_SUB_NUM                                          B_SUB_NUM                                          START_DATE_TIME                                    SIDE
    -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----
    77777733                                           77777733                                           20120625000000                                     A
    88912345                                           88912345                                           20120625000022                                     B
    88912345                                           88912345                                           20120625000028                                     B    
    
  • How to find inserted last record in the table.

    Version: Oracle 10g

    I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
    How to find inserted last record in the table 'manufacturing '.

    As I got to know that the Rowid is not a result perfect result. Please provide your inputs.

    user13416294 wrote:
    Version: Oracle 10g

    This is not a version. It's a product name. A version is 10.1.0.2 or 10.2.0.4, etc.

    I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
    How to find inserted last record in the table 'manufacturing '.

    Not possible as your data model do not answer for him. As simple as that.

    If there is a need to determine an order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or several attributes are necessary to represent this information. Your data model in this case is therefore unable to meet your requirements.

    If the requirements are valid, set the data model. In other words - your question has nothing to do with Oracle and nothing to do with the other pseudo columns in Oracle, the rowscn or the rowid. It is a question of pure data modeling. Nothing more.

  • Can we find that erased records in a table if we have no verification tables?

    Can we find that erased records in a table if we have no verification tables?
    Ex:-we have time two days back (in time)
    Version Oracle 11G

    This will happen from 11 g. 11 g, if you do not have Supplemental logging enabled before using Logminer, you would see the results like you have only. Please see reference below,
    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28319/LogMiner.htm#i1021068

    HTH
    Aman...

  • Where can I find the sound recorder files?

    * Original title: sound files recorder

    I'm really looking for someone to help me on the extraction of a file of the sound recorder, I wasn't able to save. I use windows 8.

    I tried to look for him C:\Users\James\AppData\Local\Temp for an ART_tmp file, but I couldn't find

    it.

    I tried to play the sound recorder, while I'm looking at the C:\Users\James\AppData\Local\Temp and the ART_tmp appears, but once I close the program without saving it, it will disappear.

    Anyone, where does go... greatly appreciate any help. again, I use Windows 8...

    Thank you

    James L.

    I had this same problem and found the answer here:

    http://www.surfacetablethelp.com/2014/01/Windows-8-1-sound-recorder-file-location-and-best-apps.html

    I find my record and moved to another folder.  It's a m4a file so it works then very easily through my music app

  • Using SQL to ensure the matching records are mutually exclusive.

    There are two tables defined in the following way:

    Table A

    Number 1

    Number 2

    Date

    ROWID

    Table B

    Number 1

    Number 2

    Date

    Identifier of the line

    Each table stores a call between number 1 and 2 on a specific date. The goal is to map exactly one entry of table A with exactly the record in table B

    in a mutually exclusive way. So a single call to a table must be associated with exactly one call the other table (the key is here

    A.Number1 is B.Number1 and A.Number2 = B.Number2). Because it is a relationship is many to many (the number of source and destination may be paired multiple)

    (time), I'm not able to build a series of sql statements that will allow me to get a relationship one between pairs of telephone numbers.

    I'm not allowed to develop a PL/SQL procedure, which would easily solve this problem.

    I was able to find a solution using MIN(Number 1) KEEP (DENSE_RANK FIRST ORDER BY Date) to THE (PARTITION BY x) the form x

    using temporary tables, which allows me to reach a breaking successively much many relationships (i.e. three broken bones in a 01:58 after

    an iteration, and after one iteration, I arrive at a one to one relationship). However, I can't break these relations some n number of times because it requires number n

    hard curls. Therefore, I need a sophisticated solution that will allow me to achieve a relationship one by one.

    Example of

    Table A

    Record 1

    Number 1:451923456789

    Number 2:541969432045

    Date: 29/07/2015-09:01

    Worksheet 2

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:03

    Table B

    Record 1

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:04

    Worksheet 2

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:05

    If we unite our table A and B by A.Number1 = B.Number1 and A.Number2 = B.Number2, we have 4 records. I'm looking for exactly two records.

    The criteria is to associate by the minimum of the sum of the date of the table A table B date. Therefore, the final result should match:

    (1) record 1 of table A with record 1 of table B.

    sheet 2) 2 table A with 2 record in table B.

    So we must do something to reduce the 4 records resulting from the join of two records describe as we see above.

    The result of the join:

    1st row: TableA.Record1 with TableB.Record1

    2nd place: TableA.Record1 with TableB.Record2

    Rank 3: TableA.Record2 with TableB.Record1

    4th place: TableA.Record2 with TableB.Record2

    What I'm looking for, which is easily achievable with a slider, but not with SQL:

    1st row: TableA.Record1 with TableB.Record1

    4th place: TableA.Record2 with TableB.Record2

    Note that if the minimum date condition allows us to select the necessary records, we won't get the expected results. In other words, using the minimum date.

    the results will be:

    1st row: TableA.Record1 with TableB.Record1

    Rank 3: TableA.Record2 with TableB.Record1

    (criteria - table a minimum date)

    or

    1st row: TableA.Record1 with TableB.Record1

    2nd place: TableA.Record1 with TableB.Record2

    (criteria - date minimum table B)

    Two of these results to break the rule are mutually exclusive.

    Post edited by: 3000640

    If I understand correctly, something like:

    SQL > with tableA (id, telephone1, telephone2, call_date) as)

    2. Select 1, ' 451923456789 ', ' 541969432045',

    3 to_date (July 29, 2015 09:01 ', 'dd.mm.yyyy hh24')

    4 union double all the

    5. Select 2, ' 451923456789 ', ' 541969432045',

    6 to_date (July 29, 2015 09:03 ', 'dd.mm.yyyy hh24')

    double 7),

    TableB 8 (id, telephone1, telephone2, call_date) as)

    9. Select 1, ' 451923456789 ', ' 541969432045',

    10 to_date (July 29, 2015 09:04 ', 'dd.mm.yyyy hh24')

    11 double Union all the

    12. Select 2, ' 451923456789 ', ' 541969432045',

    13 to_date (July 29, 2015 09:05 ', 'dd.mm.yyyy hh24')

    14 double)

    15 select a.id help, a.phone1 aphone1, a.phone2 aphone2,

    16 a.call_date acall_date, b.id offer, b.phone1 bphone1,

    17 b.phone2 bphone2, b.call_date bcall_date

    18 (select id, telephone1, telephone2, call_date,

    19 row_number() over (partition by numbers1, telephone2

    RN 20 order by call_date)

    tablea 21) a

    22 join (select id, telephone1, telephone2, call_date,

    23 row_number() over (partition by numbers1, telephone2

    RN 24 order by call_date)

    tableb 25) b

    26 on a.phone1 = b.phone1 and

    27 a.phone2 = b.phone2 and

    28 a.rn = b.rn;

    HELP APHONE1 APHONE2 ACALL_DATE BPHONE1 BPHONE2 BCALL_DATE OFFERS

    ---------- ------------ ------------ -------------------- ---------- ------------ ------------ --------------------

    1 451923456789 541969432045 July 29, 2015 09:01 1 451923456789 541969432045 July 29, 2015 09:04

    2 451923456789 541969432045 July 29, 2015 09:03 2 451923456789 541969432045 July 29, 2015 09:05

    John

  • Search for Windows 7 can't find partial matches - when will it be fixed or is there a workaround?

    Windows (in Windows 7 and Vista) search will find only a partial file name (and the file content I guess) match if the text is the beginning of the string. He won't find a string in a file (the file content?) name. This diminshes greatly the value of research and thought that he would have been treated here.

    Example:

    I have a file named invoicenumber12345.doc
    If I search on invoicenumber file appears in the results. If I look on number12345, 12345 or any other subset of characters that appear in the name I get nothing.

    It is therefore impossible to find files based on partial knowledge.

    Example:

    I know that I have sent a letter to Joe Smith, but I can't because I named the file lettertojoesmith.doc
    Due to the limitation of the search, if I'm not rememer the exact file name (or at least that it starts with "letterto", I couldn't find - then what is research?) Through structure file names so that you know how to find totally defeated RESEARCH capacity.

    Does anyone know when this limitation will be addressed or whether there is a solution?

    You can use wildcards like? and *.
    In your case: search for * 12345 or * joe * smith.

    In fact, it is more flexible that a simple search on partial file names.

  • Can not find the statistical record of free cell

    When I play Free Cell, at the end of the game, Windows 7 can not find the statistics file to save the results of the games which causes the game to break off and restart. I tried to remove free cell and restore without success. Can I replace the statistical record?

    I think that the statistics are stored in:

    C:\Users\\Appdata\Local\Microsoft Games\Freecell\Freecellsettings.xml

  • Matching records between 2 tables with duplicate records

    Hi all

    I need help in what follows.

    I have 2 tables Received_bills and Send_bills.

    -------------------------------------------------------

    -The DOF for Table SEND_BILLS

    --------------------------------------------------------

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

    --------------------------------------------------------

    -The DOF for Table RECEIVED_BILLS

    --------------------------------------------------------

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE),

    VARCHAR2 (5 BYTE) 'STATUS' )  ;

    INSERTION of REM in RECEIVED_BILLS

    TOGETHER TO DEFINE

    Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    INSERTION of REM in SEND_BILLS

    TOGETHER TO DEFINE

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.

    Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results

    the query I wrote is this:

    SELECT SEND.*

    REC received_bills, send_bills send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND 'rec.status =' SUCCESS

    ;

    The query results give me this

    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5

    The result of the correct application would be

    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1519A1

    The select statement that I need I want to use a loop to insert records in another table.

    Can someone help me please?

    Thanks in advance.

    Best regards

    Caroline

    Hi, Caroline.

    Caroline wrote:

    Hi all

    I need help in what follows.

    I have 2 tables Received_bills and Send_bills.

    -------------------------------------------------------

    -The DOF for Table SEND_BILLS

    --------------------------------------------------------

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

    --------------------------------------------------------

    -The DOF for Table RECEIVED_BILLS

    --------------------------------------------------------

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE),

    VARCHAR2 (5 BYTE) 'STATUS');

    INSERTION of REM in RECEIVED_BILLS

    TOGETHER TO DEFINE

    Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    INSERTION of REM in SEND_BILLS

    TOGETHER TO DEFINE

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.

    Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results

    the query I wrote is this:

    SELECT SEND.*

    REC received_bills, send_bills send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND 'rec.status =' SUCCESS

    ;

    The query results give me this

    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5

    The result of the correct application would be

    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5
    OCTOBER 10, 15 19 A1

    The select statement that I need I want to use a loop to insert records in another table.

    Can someone help me please?

    Thanks in advance.

    Best regards

    Caroline

    Want to get answers that work?  Then make sure that the CREATE TABLE and INSERT statements you post too much work.  Test (and, if necessary, correct) your statements before committing.  You have a stray "." in the first INSERT statement for received_bills and receikved_bills.status is defined as VARCHAR2 (5), but all values are 6 characters long.

    There are 5 lines in send_bills that are similar to the

    10 OCTOBER 2015 19 A1

    Why do you want that 2 rows like this in the output, not 1 or 3, or 4 or 5?  Is it because there are 2 matching rows in received_bills?  If so, you can do something like this:

    WITH rec AS

    (

    SELECT the reference, payment, code

    , ROW_NUMBER () OVER (PARTITION BY datum, payment, code)

    ORDER BY NULL

    ) AS r_num

    OF received_bills

    Situation WHERE = 'SUCCESS'

    )

    send AS

    (

    SELECT the reference, payment, code

    , ROW_NUMBER () OVER (PARTITION BY datum, payment, code)

    ORDER BY NULL

    ) AS r_num

    OF send_bills

    )

    SELECT send.datum, send.payment, send.code

    REC, send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND send.r_num = rec.r_num

    ;

    Note that the main request is very similar to the query you posted, but the last condition has changed.

    If you need to insert these lines in another table, you can use this query in an INSERT statement. There is no need of a loop, or for any PL/SQL.

  • How to find close window

    CTRL + F opens the search window where we enter a Word and find each entry as it appears in the document.

    How is - a to close the Find window when you have finished using it?

    Press ESC or click the small 'X' button in the corner of the search window.

  • Query to find the match on two areas where the third does not work...

    Faced with this one...

    Light of the example data
    SECTION     GROUPID     SUBGROUPID     COMPONENT     PNUM     USERNAME
    HVAC     AC     MOTOR          HOSE          111.1     BOB
    HVAC     AC     MOTOR          HOSE          111.2     BOB
    HVAC     AC     MOTOR          HOSE          111.3     JIM
    
    HVAC     AC     MOTOR          BOLT          411     BOB
    HVAC     AC     MOTOR          BOLT          411     BOB
    HVAC     AC     MOTOR          BOLT          411     BOB
    HVAC     AC     MOTOR          BOLT          (null)     (null)
    
    HVAC     AC     MOTOR          CLAMP          211.1     BOB
    HVAC     AC     MOTOR          CLAMP          211.2     JIM
    HVAC     AC     MOTOR          CLAMP          211.3     BOB
    
    HVAC     AC     MOTOR          STRAP          611.1     JIM
    
    HVAC     AC     MOTOR          BELT          811.3     BOB
    HVAC     AC     MOTOR          BELT          (null)     (null)
    
    HVAC     AC     MOTOR          DISC          (null)     (null)
    HVAC     AC     MOTOR          DISC          (null)     (null)
    HVAC     AC     MOTOR          DISC          (null)     (null)
         
    What I need is a list of records where the GroupID and component matching, and where they had a PNUM who were not all the same

    So in this case I would like to only these returned, Section/SubgroupID/username are not required to match on anything whatsoever, but here to view the
    additional data that may be there. Items that have PNUM which IS NULL should be ignored? Example would be the example above where the PNUM
    for a record was 811,3 while one below is null, which should not return. Its considered to be 'ok' and does not need to be reported.

    SECTION     GROUPID     SUBGROUPID     COMPONENT     PNUM     USERNAME
    HVAC     AC     MOTOR          HOSE          111.1     BOB
    HVAC     AC     MOTOR          HOSE          111.2     BOB
    HVAC     AC     MOTOR          HOSE          111.3     JIM
    
    HVAC     AC     MOTOR          CLAMP          211.1     BOB
    HVAC     AC     MOTOR          CLAMP          211.2     JIM
    HVAC     AC     MOTOR          CLAMP          211.3     BOB

    Hello

    To identify all incompatible groupid/component combinations:

    SELECT       groupid, component
    FROM       table_x
    GROUP BY  groupid, component
    HAVING       COUNT (DISTINCT pnum)     > 1
    ;
    

    To view information on all lines with these groupid/component combinations, use the query above in an IN subquery:

    SELECT  *
    FROM     table_x
    WHERE     (groupid, component)  IN
         (
              SELECT       groupid, component
              FROM       table_x
              GROUP BY  groupid, component
              HAVING       COUNT (DISTINCT pnum)     > 1
            )
    ;
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

Maybe you are looking for

  • Disable updates

    I just upgraded to version 42.0 and although my mozilla.cfg file, prefs.js file and the topic: config page shows that app.update.enabled and app.update.auto are fake, the ' Check for Updates ' button in help > on Firefox is still clickable. There is

  • Satellite Pro A60. I need to change the cd/dvd drive

    I am a complete "newbie" to this kind of help is welcome. I need to change the cd/dvd drive the current one is as good as a horse rocker with a broken leg! I also need to buy one that won't break the Bank.Thanks in advance.Countryman

  • Omni 10 Tablet: AC charger for omni 10 Tablet have can buy a

    Hi all Anyone know where to buy a charger for 10 to an Omni 10 Tablet x 64 window. I live in Perth Western australia.

  • Windows 7 not valid

    I made the scan MPE and got this code can someone help me? Diagnostic report (1.9.0027.0):-----------------------------------------Validation of Windows data--> Validation code: 50Validation caching Code online: n/a, hr = 0xc004f012Windows product ke

  • Where is utility windows install cleanup located?

    original title: utility windows install cleanup I can't find Installer Cleanup utility anywhere. Is is still available and if so where?