How can I select the first date (at least) and the corresponding date of two different tables source?

I have 2 tables, INVOICE and INVOICE_REFNUM similar to below. I'm writing a query that withdrawing the first date (less) for a single record remaining the two tables. Each table records the receipt of invoices, but according to the source of the received invoice some may reside in INVOICE_REFNUM and others the INVOICE table. I also use DECODE on the topic of INVOICE_SOURCE, when the date less is taken from the INVOICE table that contains that field, so if the date is in the field INVOICE_REFNUM DECODE is not necessary. Example:

INVOICE (table)

INVOICE_GID INVOICE_SOURCE INSERT_DATE

ABC. AVRT123 I HAVE 11/03/2012-15:49:32

ABC. CNWY234 G 12/03/2012 14:07:30

ABC. UPGF678 M 15/03/2012 20:21:54

INVOICE_REFNUM (table)

INVOICE_GID INVOICE_REFNUM_QUAL INVOICE_REFNUM_VALUE INSERT_DATE

ABC. AVRT123 SOURCE ACS 11/03/2012 14:49:32

ABC. CNWY234 SOURCE CSA 12/03/2012 13:07:30

ABC. UPGF678 SOURCE ACS 15/03/2012 21:21:54

My decode statement is: DECODE ("INVOICE_SOURCE, 'I', 'IDE', 'G', ' Auto-Pay", ', 'Manual')

If I were to write a query on these two tables, the output will resemble the following:

INVOICE_GID INVOICE_SOURCE INSERT_DATE

ABC. AVRT123 ACS 11/03/2012 14:49:32

ABC. CNWY234 ACS 12/03/2012 13:07:30

ABC. UPGF678 Manual 15/03/2012 20:21:54

I worked on it for 2 days, and I was able to pull a date by using the following SQL code, but cannot determine how to extract the corresponding source:

SELECT THE LEAST (GLOGOWNER. INVOICE_REFNUM. INSERT_DATE, GLOGOWNER. THE INVOICE. INSERT_DATE) AS 'DATE OF THE INVOICE.

GLOGOWNER. THE INVOICE. INVOICE_GID,

DECODE (GLOGOWNER. THE INVOICE. INVOICE_SOURCE, 'I', 'IDE', 'G', 'Auto-Pay', ', 'Manual').

GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_VALUE

OF GLOGOWNER. INVOICE

LEFT JOIN GLOGOWNER. INVOICE_REFNUM

ON GLOGOWNER. THE INVOICE. INVOICE_GID = GLOGOWNER. INVOICE_REFNUM. INVOICE_GID

WHERE GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_VALUE = "ACS."

AND GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_QUAL_GID = 'SOURCE '.

AND GLOGOWNER. THE INVOICE. INVOICE_TYPE = 'I '.

ORDER OF GLOGOWNER. THE INVOICE. INVOICE_GID

Any help is greatly appreciated!

Best regards

-Adam

Hello

Is that what you want?

SELECT i.invoice_gid

CASE

WHEN ir.insert_date<= i.insert_date ="" then ="">

WHEN i.invoice_souce = 'I' and THEN 'EDI '.

WHEN i.invoice_souce = 'G' THEN 'debit '.

WHEN i.invoice_souce = am' THEN 'manual '.

END AS invoice_source

, The LEAST (i.insert_date, ir.insert_date) AS insert_date

I have the Bill OF

JOIN invoice_refnum ON i.invoice_gid = ir.invoice_gid ir

WHERE ir.invoice_refnum_value = 'ACS '.

AND ir.invoice_refnum_qual_gid = 'SOURCE '.

AND i.invoice_type = 'I '.

ORDER BY i.invoice_gid

;

There is no reason to do an outer join if you only want the lines with specific values anyway.

What happens if the 2 tables have exactly the same invoice_date?  The query above takes the invoice_source of invoice_refnum in this case, but that can easily be changed.

Or the other of the insert_dates can be NULL?

I hope that answers your question.

Otherwise, thank you post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also after the results you want from these data (otherwise what you have already posted).

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: https://forums.oracle.com/message/9362002#9362002

Tags: Database

Similar Questions

  • How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    I have only:
    D: / images (where are necessary + not need files)
    -a list with only the necessary files
    -a list with new names for the files needed
    Thank you.

    Hi Pustiu,

    Thanks for posting in the Microsoft Community.

    You want to know how to select the files in a folder using a list with the files you want and after that rename only the files using another list with desired new names.

    I would have you post your query in the TechNet forums because it caters to an audience of it professionals.

    Your query will be better addressed there.

    Check out the link-

    http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/threads

    We know if you need help. We will be happy to help you. We, at tender Microsoft to excellence.

    Thank you.

  • How can I set the time axis on my waveform table to show run time that is to say whenever I start the program I should have 0 as the starting point

    How can I set the time axis on my waveform table to show run time that is to say whenever I start the program I should have 0 as the starting point. I've been messing around with the without success. I'm under Labview 2012.

    Thank you!

    Townes wrote:

    I can't understand what you mean. I have no formal training with labview. It took me a long time to write the simple program that I joined. Any guidance would be greatly appreciated!

    Its pretty normal for a beginner to take the time to write code. Right-click the map of waveform > Create > property node > historical data, you will get a property node, keep this at the beginning of the code and create a constant. You can also go to the VI properties and > run and select "clear indicators when it is called.

    I recommend you to go through the basic materials of LabVIEW which will give you an understanding on the basics of bases/components of LabVIEW.

  • How can I change the "right click" menu for a table control?

    Hello

    How can I change the "right-click menu" of a table control. I would like to be able to remove the ability to add or remove columns and maybe more selections. I want to keep the possibility of

    Add or remove lines

    Right-click on your table.  Then go to advanced-> DURATION Shortcut Menu-> Edit.

  • How can I make the menu title of a different color when it is horizontal Spry menu menu?

    How can I make the menu title of a different color when it is horizontal Spry menu menu?

    Dreamweaver CS5.5

    Apple OS X.6.8

    Display of the site to: http://Dorsay-Easton-Indian-law.com/staging/index.html

    Steps to follow:

    1. click on the link to land on the home page

    2 link see Home in the Spry horizontal navigation menu

    Real:

    Title of the home menu is the same color as all the others.

    Expected:

    The title of the active menu is color: #FFC.

    I was hoping that a: active would give me this feature, but it's not how it is described. All suggestions are welcome!

    The tag BODY nothing that I tried in the editable model. This is why I wonder how to disconnect the model individual pages. Adding an ID to each body tag is a condition sine qua non of the how-to page that you provided.

    You are not theeditable in a template tag.

    You are the attributes of theeditable tag.

    Do not unplug the model child pages.

    Specify editable tag attributes in a template

    http://help.Adobe.com/en_US/Dreamweaver/CS/using/WScbb6b82af5544594822510a94ae8d65-7aa3a.h tml

    In the model:

    1. Select ittag (in the tag selector, or click inside the)tag in Code view)
    2. Modify > templates > make attribute editable
    3. Select the code in the drop down attribute
    4. If there is no ID attribute then click Add and type the ID in the next dialog box
    5. Attribute: ID
      Check the box 'Make attribute editable '.
      Enter anything in the field of the default label for example foo
      Ok
    6. Dreamweaver will change thetag to read
    7. The ID is now editable
    8. Save the model and update the child page

    In each page of the child:

    1. Edit > properties of the model
    2. Select the id attribute in the list (it's probably the only one listed)
    3. Change its name in the box to any name matches your CSS rule for the active state of the page
    4. Ok
    5. Save
    6. Download
  • How can I select the language after installation of Adobe Acrobat XI?

    I installed the full version and Adobe Acrobat XI pro multilingual. The installation process is in English and I was never asked to select the language. Then, to my surprise, the software works in German. How can I change the language? Now, I don't understand the menu.

    Thank you.

    Hi Desmag,

    Please go to Edition Acrobat > Preferences > language and change the language of the application of English to 'pick at the start of the application.

    Let us know if this helps,

    Kind regards

    Sandrine

  • How can I get the tabs colorful to use different distinct colors for 2 gmail accounts?

    Under Firefox 29.0.1 iMac OSX 10.9.3. I have multiple Google accounts: 2 1 Google Calendar and gmail accounts. Colorful tabs add-on will allow me to choose a color for a gmail account, but it also uses this same color for the other gmail account. How can I get the different colors on 2 gmail accounts?

    In addition, colorful tabs is also the same for my homepage (google.com) and my google calendar. How can I get different colors on these 2?

    Personally, I use 'Fabtabs' for my mozilla FireFox.

    https://addons.Mozilla.org/en-us/Firefox/addon/FabTabs/

    This add-on has problems like that when I use it.

  • Select Max (Date) in two different tables...

    Dear all,

    I need the date of last update of two different tables, I mean max (date). We will update one table at a time. Updated once I need to take the last update.

    It can be either in table A table B.

    for example.

    Table A

    Date of the ID

    100 16/05/2014

    101 20/05/2014

    102, 22/05/2014

    Table B

    Date of the ID

    100 04/06/2014

    101, 26/05/2014

    102 21/05/2014

    I need the date of table B (101 26/05/2014) last updated date...

    Hello

    Another way, using much more GRAND:

    SELECT LARGER (max1, max2) x

    FROM (SELECT MAX (mydate) max1

    OF mytable_a

    )

    (SELECT MAX (myotherdate) max2

    OF mytable_b

    )

    ;

    Best regards

    Bruno Vroman.

  • How can I select the language of the books?

    How to select the language of the books. All iBooks books shows to me are by default in German. I want to change that, how?

    Language is determined by the iBooks store that you download content. The only way to change the language is to change stores > change your iTunes Store country or region - Apple Support

  • How can I select the area I want to bound, to another page?

    Hello

    I've been creating multiple stand alone PDF files with links to various documents in a given PDF file.  Until yesterday that I would choose the button Link, move my cursor to the top left corner of the area to be selected, press the button and drag a box over the area that I selected.  It was working fine.  Then, BOOM, all of a sudden when I do that now it doesn't let me select the area I want, it will show a fixed which seems to be broken-line formatting above or below the box I want.  Is there a setting somewhere which might have changed?

    Davey

    Make sure that you don't have the snap to the grid selected option.

    In Acrobat 8, it's under the view menu.

  • How can I find the top row of a single table, split among several images in each image.

    Hi all.

    Thanks in advance.

    You can browse all the cells in a row column * and ask the first insertion of a text on his cell point user.user parentTextFrames [0].

    If the ID value has changed, the cell is in a different text frame. As well as its line.

    CC-2015, it might be a little different, because we have a new type of cell: CellTypeEnum.GRAPHIC_TYPE_CELL (not insertionPoints pave the way).

    You can also:

    Reproduce all text blocks in history, in that the table is sitting and control for unique tables in duplicates.

    Uwe

    * edit

  • How can I identify the corresponding lines when lead and trolling can be used for several similar values in their?

    I use:

    Oracle SQL Developer (3.0.04) build hand - 04.34 Oracle Database 11 g Enterprise Edition 11.2.0.1.0 - 64 bit Production


    Examples of data

    Table

    with t as)

    Select to_date('8-18-2013','mm-dd-yyyy') dt, "123_' ticket_origin, ticket_destination '123', startid 101, 101 origin, destination 0, 'origin' objecttype, amount 85, 100 area union double all the

    Select to_date('8-18-2013','mm-dd-yyyy'), 123', '123_", 0, 101, 103, 'destination', 85, 100 of all the double union

    Select to_date('8-18-2013','mm-dd-yyyy'), 123', '123_", 103, 0, 0, 'destination', 85, 100 of all the double union

    Select to_date('8-17-2013','mm-dd-yyyy'), 124. _', ' 124. ', 105, 105, 0, 'origin', 150, 200 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), 124. _', ' 124. ', 105, 106, 0, 'origin', 150, 200 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '124.', 124. _', 0, 0, 106, 'destination', 150, 300 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '124.', 124. _', 105, 0, 106, 'destination', 150, 300 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '127_', '127', 108, 108, 0, 'origin', 50, 600 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '127', '127_', 0, 0, 110, 'destination', 50, 600 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '127', '127_', 0, 0, 110, 'destination', 75, 600 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), 125. ' _', ' 125 '., 108, 108, 0, 'origin', 60, 800 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), 125. ' _', ' 125 '., 108, 112, 0, 'origin', 60, 800 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), ' 125. ', '125', 108, 108, 0, 'origin', 60, 800 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), ' 125. ', '125', 109, 108, 0, 'origin', 60, 800 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), ' 125. ', 125. _', 0, 0, 112, 'destination', 60, 700 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), ' 125. ', 125. _', 108, 0, 112, 'destination', 60, 700 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '125', ' 125. ', 0, 0, 109, 'destination', 60, 900 from all the double union

    Select to_date('8-17-2013','mm-dd-yyyy'), '125', ' 125'., 108, 0, 109, 'destination', 60, 900 double

    )

    Is there a way to check date of consolidation for correspondence ticket_origin and ticket_destination when there are two or more lines of difference between them, which does not allow me to use result delay or function. It is also possible do it without using the amount column?

    I also want to identify if they are in the same region, when it is associated with (that I believe works after getting sorted table like so below then use lead lag after having de facto order)

    I'm trying to get something like this table

    with results like)

    Select to_date('8-18-2013','mm-dd-yyyy') dt, "123_' ticket_origin, ticket_destination '123', startid 101, 101 origin, destination 0, 'origin' objecttype, amount 85, 100 area union double all the

    Select to_date('8-18-2013','mm-dd-yyyy'), 123', '123_", 103, 0, 0, 'destination', 85, 100 of all the double union

    Select to_date('8-17-2013','mm-dd-yyyy'), 124. _', ' 124. ', 105, 105, 0, 'origin', 150, 200 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '124.', 124. _', 105, 0, 106, 'destination', 150, 300 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '127_', '127', 108, 108, 0, 'origin', 50, 600 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '127', '127_', 0, 0, 110, 'destination', 50, 600 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), 125. ' _', ' 125 '., 108, 108, 0, 'origin', 60, 800 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), ' 125. ', 125. _', 0, 0, 112, 'destination', 60, 800 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), ' 125. ', '125', 108, 108, 0, 'origin', 60, 700 Union double all the

    Select to_date('8-17-2013','mm-dd-yyyy'), '125', ' 125. ', 0, 0, 109, 'destination', 60, 900 double

    )

    You need to research rules business more to clarify and apply the mapping one.  The main secret is probably to match the values of ticket.

    Under use a t_view of view with the addition of PK (RID) to the table.  Some discrepancy could be solved by adding more rules for mapping and correcting the expected result entry errors

    SQL > desc t_view

    Name

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

    RID

    DT

    TICKET_ORIGIN

    TICKET_DESTINATION

    STARTID

    ORIGIN

    DESTINATION

    OBJECTTYPE

    AMOUNT

    AREA

    with

    T1 as (select * from t_view where OBJECTTYPE = 'origin'),

    T2 as (select * from t_view where OBJECTTYPE = 'destination').

    map as (t1.rid select origin_id, t2.rid from t1 DESTINATION_id, t2)

    where t1. TICKET_ORIGIN = t2. TICKET_DESTINATION

    and t1. TICKET_DESTINATION = t2. TICKET_ORIGIN

    -Add rules to apply the one-to-one mapping

    and t1.amount = t2.amount

    and t1. STARTID = t1. ORIGIN

    and t2. STARTID = t2. ORIGIN),

    like map2)

    Select origin_id gid, origin_id rid of card

    Union of all the

    Select origin_id gid, DESTINATION_id rid of card)

    Select t_view.* card2, t_view where map2.rid = t_view.rid

    order of map2.gid, map2.rid

    /

       GET RID OF THE DT TICKE TICKE STARTID ORIGIN DESTINATION OBJECTTYPE AMOUNT AREA

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

         1 18 AUGUST 13 123_ 123 101 101 0 origin 85 100
         3 18 AUGUST 13 123 123_ 0 0 destination of 103 85 100
         4 17 AUGUST 13 124. _ 124. 105 105 0 origin 150 200
         6-17 AUGUST 13 124.  124 _ 0 0 destination of 106 150 300
         8 17 AUGUST 13 127_ 127 108 108 0 origin 50 600
         AUGUST 9-17 13 127 127_ 0 0 destination of 110 50 600
        11-17 AUGUST 13 125. _ 125. 108 108 0 origin 60 800
        15-17 AUGUST 13 125.  125 _ 0 0 destination of 112 60 700
        13-17 AUGUST 13 125.  125 108 108 0 origin 60 800
        17 17 AUGUST 13 125 125. 0 0 destination of 109 60 900

    10 selected lines.

  • How can I combine the 2 vertical cells in a table 2 ranks, while retaining his other 4 columns NONmerged?

    I use Dreamweaver CS5 and wonder if there is a way to merge 2 vertical cells centralized in a table of 2 oars, while cells of his other 4 columns (2 on each side) NONmerged.   It is possible, please?   I go to:

    MODIFY-> TABLE

    but the function "MERGE CELLS" which seems it is dark, while the other options are, however, ready to be selected.   I've experimented with trying to select the two cells to merge, but that did not work or the other.   This could be a bug in the software?   Or could I do something naively?

    Happy 2012 at all :-)

    DreamWeaverBeliever wrote:

    I use Dreamweaver CS5 and wonder if there is a way to merge 2 vertical cells centralized in a table of 2 oars, while keeping other cells 4 columns (2 on each side) NONmerged.   It is possible, please?   I'll EDIT--> TABLE, but the function "MERGE CELLS" which seems it is dark, while the other options are, however, ready to be selected.   I've experimented with trying to select the two cells to merge, but that did not work or the other.   This could be a bug in the software?   Or could I do something naively?

    Happy 2012 at all :-)

    Is this possible?  Yes it is possible.  May be a bug in the software?  No, it's not a bug in the software.

    To merge cells, select the cells that contiguous with your mouse.  Click on a cell and with the left mouse button pressed, drag it to other cells that are to the right and below.

    You can now use merge cells and it should work.

    The alternative is to work in code view and change the code to look like this:

     

    I hope this helps.

  • I want to loop through the data from two different tables using for loop where the query should be replaced at runtime, please help me

    I have the data into two table with the structure of similar column, I want to loop through the data in these two tables

    based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    declare

    l_statement varchar2 (2000);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: =' select * ab ';

    on the other

    l_statement: =' select * from bc';

    end if

    I'm in execute immediate l_statement - something like that, but I don't know

    loop

    dbms_output.put_line (i.a);

    end loop;

    end;

    Something like that, but this isn't a peace of the code work.

    Try this and adapt according to your needs:

    declare

    l_statement varchar2 (2000);

    c SYS_REFCURSOR;

    l_a number;

    l_b varchar2 (20);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: = "select a, b, AB;

    on the other

    l_statement: = "select a, b from bc;

    end if;

    --

    Open c for l_statement;

    --

    loop

    extract the c in l_a, l_b;

    When the output c % notfound;

    dbms_output.put_line (l_a |') -' || l_b);

    end loop;

    close c;

    end;

    /

  • I use my more than any other genealogy bookmarks folder. I recently discovered that he was missing. How can I select which restore date?

    I use the most recent addition of the Foxfire. I see all the options on the restoration. I don't know that we choose. I understand that I will lose everything I have added since that date. So I guess I should start from the most recent or the last time that I definitely know that I saw.

    OK, I found the answer to my own question. I looked through my history and found one of the sites that I use a lot, then I looked liked down the list until I found a message that I had read, checked to see when I read this mail and restored my favorites from that day here. I have my favorites of genealogy back.
    For each of you who make genealogy, you may have an idea of how many bookmarks I had in this category. Now the question is how it happened? I don't want it to happen again. Maybe I'll watch just for him whenever I load Firefox upward.

Maybe you are looking for

  • problems of ultra maxx charges with a power cord

    Sometimes my Maxx will begin charging when I plug, sometimes it requires a reboot before it will start to load. I tried a new power cord from Verizon and the results are the same. I got the phone because he is out, and the problem started a couple of

  • Cannot load of DCR-HC30 to computer

    I need to transfer some videos of our old DCR-HC30 to our PC running Windows 7 (64-bit), and I don't have the original disc that came with the camera. How can I find the right software to achieve this. Thank you. Jim

  • HP 3522 won't print in black

    HP 3522 won't print in black - all new cartridges - replaced black for printing Sun and, now, not at all - has retried original cartridge - all basket original hp.  Tried every hp online help - none worked - out warrentry as on March this year.

  • Intel SSD on Latitude E6410?

    I tried adding a 160 GB Intel SSD to a new E6410 and the bios does not recognize, no matter the SATA setting in bios... AHCI, ATA, RAID, etc. No main device in the bios. I used acronis to move my data to the drive, so I know it works. Any ideas?

  • VPN IS CONNECTED BUT CANNOT ACCESS THE INTERNAL NETWORK

    I tried to set up a simple customer vpn using this document http://www.Cisco.com/en/us/products/sw/secursw/ps2308/products_configuration_example09186a00801e71c0.shtml VPN IS CONNECTED BUT CANNOT ACCESS THE INTERNAL NETWORK BEHIND "RA"... 6.3 (5) PIX