Last address and previous address in the last 30 days

People in the morning.

I need to know to all customers whose address has changed, based on the date of entry into force. The query should be based from the 1st June 12 effective date and not SYSDATE. So, we want to check the MAX (effective_date) is < = 1 June 12 and entry into force of the previous address is between 2 May 12 and June 1, 12 (30 days). This suggests that the address has changed. For the sake of the argument, the postal Code is enough to make the difference that the address has changed for now.


According to the data, I only take customer 1002 but not 1001, 1003. With respect to the customer ID 1003, although his address has changed in the last 30 days, we aren't interested as the effective address June 1 has been good for a long time.

In addition, even if the address for the customer ID 1001 changed twice in this period, I'm only interested for the last two addresses.

Table CUST_ADDRESS
CREATE TABLE CUST_ADDRESS
  (
    "CUST_NO"  VARCHAR2(4 BYTE) NOT NULL,
    "STREET"   VARCHAR2(20 BYTE),
    "CITY"     VARCHAR2(20 BYTE),
    "STATE"    VARCHAR2(2 BYTE),
    "ZIP_CODE" VARCHAR2(9 BYTE),
    "EFFECTIVE_DATE" DATE
  );
INSERT the Script
Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1001','123 Picket Fences','Santa Ana','CA','92704',to_date('31-MAY-12','DD-MON-RR'));
Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1001','12259 Circular Dr','Irvine','CA','92705',to_date('10-APR-12','DD-MON-RR'));
Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1001','22 Green Road','Newport Beach','CA','92709',to_date('03-JAN-12','DD-MON-RR'));

Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1002','12 Parkside Dr','Chicago','IL','60601',to_date('20-MAY-12','DD-MON-RR'));
Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1002','3200 Court Road','Indianapolis','IN','46201',to_date('02-MAY-12','DD-MON-RR'));

Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1003','24 Jaeger St','Bellingham','WA','98225',to_date('01-JUL-12','DD-MON-RR'));
Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1003','145 NE 38th St','Fort Lauderdale','FL','33334',to_date('18-JUN-12','DD-MON-RR'));
Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1003','212 Coral Drive','Miami','FL','33010',to_date('01-JAN-95','DD-MON-RR'));
Thanks to a bouquet.

Published by: Roxyrollers on July 26, 2012 09:35

Something like that

SQL> ed
Wrote file afiedt.buf

  1  select *
  2    from (
  3  select ca.*,
  4         max(effective_date) over (partition by cust_no) max_eff_date,
  5         lag(effective_date) over (partition by cust_no order by effective_date) prior_eff_date
  6    from cust_address ca)
  7   where prior_eff_date between date '2012-05-02' and date '2012-06-01'
  8*    and max_eff_date <= date '2012-06-01'
SQL> /

CUST STREET               CITY                 ST ZIP_CODE  EFFECTIVE MAX_EFF_D PRIOR_EFF
---- -------------------- -------------------- -- --------- --------- --------- ---------
1002 12 Parkside Dr       Chicago              IL 60601     20-MAY-12 20-MAY-12 02-MAY-12

Justin

Tags: Database

Similar Questions

  • AutoFill stop working on my site abt 09/01/2013. He remembered entered previous but not new his and previous entries in the menu auto-fill showed up to 2 X.

    I checked and I started: Firefox history, will not be remembered: always pvt mode, do not: history of compensation when I close the browser, restarted in safe mode session... I erased from history and reset Firefox manually, and now he remembers only the 1st thing you type and nothing more. Running Windows XP Pro and a another PC with same problem turn to W7. This has been great for years of work and suddenly stopped. TNX

    Hello scott, this is a known bug that is addressed in the next version of firefox. in the meantime, you can try running beta of firefox that already contains the fix: https://www.mozilla.org/firefox/beta/

  • Keyboard shortcut for "next" and "previous image", or the previous and following layers

    Hello

    I host and I like drawing with Photoshop paint tools, but to animate I need to "flip" - which is just quickly move from one drawing to the next, as you would with sheets of paper size: hunting and clicking the arrows is not feasible.

    Shortcut keys, or assignable buttons for previous and next images in the animation - or, more simple, for the previous and following layers function keys - would solve this problem completely.  This improvement could make Photoshop a viable animation program, in competition with paper plastic and Flipbook Animation.

    Is there at least a way I can download an add-on that would do this?

    Thank you

    Joe

    Do you mean something like:

    http://help.Adobe.com/en_US/Photoshop/CS/using/WSF7DD9B60-7866-4F01-915e-DE39F672E418a.htm l

    http://help.Adobe.com/en_US/Photoshop/11.0/WSF7DD9B60-7866-4F01-915e-DE39F672E418a.html

  • I want to cancel my membership and it is within the first 30 days. How can I do this? This forum seems to be my only option to get help, you do not have a phone number to call?

    I want to cancel my membership of the Adobe Creative cloud and it is always in the first 30 days of purchase.  However, I need help to do this, as this forum is the only form of communication you have? Please help, thank you in advance.

    Kim

    Look through the links below and use the option to chat if needed for your situation:

    Cancel your subscription or membership. Creative cloud

    https://helpx.Adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

    https://forums.Adobe.com/thread/1703848

    Chat support - the link below click the still need help? the option in the blue box below and choose the option to chat...

    Creative cloud support (all creative cloud customer service problems)
    http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN )

  • VM growth over the last few days N derived metric

    You are looking for assistance in creating a derived metric that would take a point in the metric of time of there are say 6 months, "poweredOnVMCount", he subtract from the current "poweredOnVMCount" and divided it by the number of days between the two measures, effectively providing the daily growth. Any help would be appreciated.

    Thank you

    Joshua

    You can use a replace a variable in the string using the "$", for example $numdays.

    Try something like this (the scope is a VMWCluster):

    then = null

    numdays = 180

    While (then == null) {}

    try {}

    String query = "VMWCluster:name virtualMachinesPoweredOnCount =" $scope.name "for day 1 day $numdays»

    then = max (server. QueryService.queryObservations (query))

    }

    catch (Exception e) {}

    numdays-

    }

    "+ numdays ++ +" days ago there was "+ then +"VM under tension.

    My result:

    56 days ago, there were 3.0 VMs under tension

    Kind regards

    Brian Wheeldon

  • 2 available drives on the points of RECOVERY and OS (C) of the system and restore the protection settings

    Greetings! I am very confused and need help. Looking for just my restore points.

    I am interested in the protection of the system, I clicked on the system protection and under the protection option I

    available from 2 discs on protection RECOVERY settings (it looks like folder sign) and OS (c :)) system)

    Protection of RECOVERY: off

    OPERATING SYSTEM (C :)) System Protection is enabled. I clicked on configure I activated the setting to restore system and previous version of the files. Maximum use of 2% (10,00 GB), use current 962,89 MB

    Now, my question is this, if recovery protection be ON? When I click on configure, check "turn off system protection"

    What is the right configuration? Help, please. I hope I'm not confusing you either.

    No, do not turn on System Protection for the system recovery disk. Which is locked and should only be used when you need to do a factory restore (that reinstalls the operating system). Just keep the System Restore enabled for the system partition on which your Windows installation exist. Releasing it's easy: with Windows | ActiveWin | Laptops | Microsoft MVP

  • Is there an easy way to get the previous record in the Apex?

    I'm new to APEX/Oracle, but have a lot of expierence as a mainframe programmer and some experience with SQL.

    I have been instructed by my boss to create a set of pages in an application like this.

    Page 1: Select an employee name and go to Page 2.

    Page 2: View employee biography information.
    Add a 'Next employee' button and a button "Previous employee" who picks the previous employees respectively biography info.

    Essentially, he wants a query with information biography of each employee with an employee selected on page 1, used as pointer to start.

    I built successfully "select the name of an employee on page 1" and "show its info on page 2" with a query that returns a single record.

    What I can not know is how to get a next and previous button for the next or previous record in a record multi query, using the initially selected employee as intial pointer.

    Is their an easy way to build this using functionailty of integrated APEX, or will it require programming to reach this requirement?

    Just realized that I didn't fully answer your question. According to the number of employees, you can create a collection to contain all the information and who travels with buttons. Or you could include a calculation to transmit the current employee, previous and next to your second page using the standard apex_application.gf01... GFN see the creation process to get the id of current line
    Keep smiling,
    Bob R

  • JavaScript anomaly on the number of days between two dates

    Use ApEx 4.0, I found an anomaly in a javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past and present is the or before March 10, 2013, and the current_date lies between 10 March 2013 and November 3, 2013, the number of days will be from 1 day to less than the actual number. Between November 3, 2013 and on 4 November 2013, the increments of number by 2, then the count will be accurate from this date forward.

    Here are some examples:

    March 10, 2013 = 69 days of December 31, 2012
    March 11, 2013 = 69 days of December 31, 2012
    March 12, 2013 = 70 days of December 31, 2012

    November 3, 2013 = 306 days in December 31, 2012
    November 4, 2013 = 308 days in December 31, 2012

    11 March should be 70 and 12 March should be 71. November 3 is 307 and 4 November corrects the number of fake, which began March 11.

    Change the past_date to March 10, 2013 produces the following:

    March 10, 2013 = 0 days of March 10, 2013
    March 11, 2013 = 0 days of March 10, 2013
    March 12, 2013 = 1 days of March 10, 2013

    But change the past_date to 11 March 2013, product of the correct numbers:

    March 11, 2013 = 0 days of March 11, 2013
    March 12, 2013 = 1 days of March 11, 2013
    March 13, 2013 = 2 days of March 11, 2013

    I would certainly all help to determine the cause of this anomaly. Here's the javascript code:

    var w1 = ($v ("P48_PAST_DATE"));
    W1 = (w1.toString ());
    vmon var = (w1.substr (3.3));
    vyr var = (w1.substr (7));
    var r = (vyr.length);
    If (r == 2)
    vyr. = (parseFloat (vyr) + 2000);
    vday var = (w1.substr (0.2));
    var y = (vmon.concat ("", vday, ",", vyr));
    y = Date.parse (y);

    var w2 = ($v ("P48_CURRENT_DATE"));
    var vmon2 = (w2.substr (3.3));
    var vyr2 = (w2.substr (7));
    var vday2 = (w2.substr (0.2));
    var x = (vmon2.concat ("", vday2, ",", vyr2));
    x = Date.parse (x);

    var numdays = (x - y);
    numdays = (Math.floor(numdays / 86400000));
    $s ("P48_NUMBEROFDAYS", numdays);

    Did you google for something like "javascript number of days between two dates. I think you will find the explanation to this observation:

    This method does not work correctly if there is an advanced economies jump between the two dates.

    There are examples available to calculate the difference between two dates.

  • I want that my address book to view all entries by first or last name and have filled all the information accordingly.

    Original title: address book

    I want that my address book to view all entries by first or last name and have filled all the information accordingly. However, I have a mixture of the first name and the name of the list alphabetically when I scroll down tom insert name in an e-mail message. My list of contracts is organized by all the names first. How can I sync the address book to match the list of contacts?

    Hi tgblueblade,

    1. what email program are you using?

    2 are. what device or software you using Sync?

    If you use Windows contacts, then this isn't the ability to synchronize the list of Windows contacts to be identical to the list of e-mail contacts.

    Manage your contacts

    http://Windows.Microsoft.com/en-us/Windows-Vista/managing-your-contacts

    I hope this helps!

    Halima S - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Since last week, I had a problem loading my Hotmail contact list addresses in the bar 'To '. It does not occur in Internet Explorer

    Problem with Hotmail. Usually when I start typing an address that is in my contact list, he fills automatically. Now I just get a circle going round and round. If I go to my contact list and select the address and click 'send email' will initially, it disappears in a second or two. To send a message, I have to enter the entire e-mail address in the field "to". This problem started about a week or two ago and doesn't happen when I connect to Hotmail using Internet Explorer.

    It left me speechless. Still the same problem. I noticed that sometimes the auto-fill starts working for a few seconds, then I get the spinning wheel.
    I will try to spend some time on it this weekend.

  • Why most of the tabs open empty with the label "New tab" and "topic: vacuum ' in the address line to the restart of Firefox since installing Firefox 28?"

    I have a system dual-bootable Windows Vista SP2 and Firefox updated to 28 on both systems. Since the update of the tabs more reopen empty with the label "New tab" and "topic: vacuum" in the address line of Firefox is restarted. The tabs that open correctly seem to be those who in fact, I was at the session of prefious. I can recover the missing tabs using the Session Manager to pick up a previous session, but of course it does not pick up the tabs open in future sessions. It seems that the tabs that I go to the session recovered are saved correctly, as indicated above, but which are not revisited in the context of the use of the session retrieved will drop the URL next time that I open Firefox it again.

    jdgale:

    I don't have the time to do it. However, 29 is just around the corner and we will put in the channel of exit 29, then hope that the issue is not you.

    P.S. I had originally chosen your last answer as the solution that you have migrated more to 29 but it seems that you have taken off. I'll be marking your last answer as the solution so that we can get out of the queue.

  • I changed my internet provider and so I have the new email address. How can I delete my old e-mail address and put them in a new in Outlook express?

    I changed my internet provider and so I have the new email address.  How can I delete my old e-mail address and put them in a new in Outlook express? AND another problem, if I want to send pictures by e-mail... default .it my no more used by email, not allowing to send because I do not agree with them. Thank you

    original title: outlook express

    XP was the last version of Windows to use Outlook Express and that you are in a forum of Vista. Assuming that Windows Mail:
     
    Tools | Accounts and add the new address/provider and remove the old.
     
    Once the old account is removed, your second issue must be without object.
  • McAfee: installed mcafee yesterday and will be unprotected on computer icon box is blue once you have entered an address in the address box, WHY?

    have not used this computer (inspiron, dell 1501) 6 months purchased a new computer in December last year. Now want to start this computer installed mcafee yesterday and will be unprotected on computer icon box is blue once you have entered an address in the address box, WHY? NO PROTECTION.

    http://www.McAfee.com/us/support/index.html

    Link above is for McAfee Support.

    They will help you with your problem of McAfee.

    See you soon.

    Mick Murphy - Microsoft partner

  • WHATS WRONG WITH WINDOW 7 (camera and scanner Wizard is the last straw that made my VERY loyal windows back)!

    Why are you people FORCING me to go apple?
    I was a supporter of the EXTREME of windows from the day I started working with computers until 17:59 today!
    I have jperchased a new laptop a month for our company. It came with WINDOWS 7. I plugged in our digital camera today a WIZARD of SCANNER & CAMERA No. found? UH... "It's funny," I thought I went to see what was not configured right. AFTER 6 HOURS. I came to the conclusion that windows FAIR BAD! Under XP I could plug in the camera, one an Assistant came...   He asked "WHAT" can they DO YOU LIKE US... Copying photos to my computer using assistant camera and scanner window was my answer... AND BAMMM, WE WENT!  It seems NOW I MUST IMPORT EACH PHOTO ON MY $ GB SD CARD that IS IN THE CAMERA... NOT TO CHOOSE WHAT I WANT TO IMPORT! I CALLED WINDOW AND THEY WANT THE SAME MONEY OF ME TALKING ON THE PHONE! THE $ LAPTOPS AND DESKTOPS % WE HAVE OWNED IN THE LAST * YEARS WASN'T ENOUGH!   I WILL NOT BUY! WINDOWS ANYTHING NEVER NEVER NEVER NEVER IF I DON'T GET THIS TREATY! I (AS WELL AS THE OWNERS OF WINDOWS OF MOSE) DO NOT DESERVE TO HAVE OUR LOYALTY SHOT LIKE THAT!  E-mail address is removed from the privacy * if someone WANTS TO HELP. It IS on February 16, 2010... IF I can NOT GET this SOLVED BY 01/03/2010 I sell all our computers and apple FULL ON more I take 2 working days and to picket of the Redmond Office with my colleagues and my very good friend Steven Swartz since the San Francisco Chronicle!

    I wanted to say something but decided against him.

    CARI you are incredibly patient.

    Well I've changed my mind again.

    If you download say Live Photo gallery (free), it will be one of the options that is available to your device picture is connected (I have a Canon SD 750)

    Select Import with Windows Live Photo Gallery and it will allow you to choose what to import.

    http://download.live.com/Photogallery

    Due to several suites of law (EU) Microsoft was forced to leave out some old features, but most can be obtained by download.

  • I hate the new address bk; don't send as before. I type a few characters and silly stuff enters the addr box, then rejected mail. How to go bk old way?

    If I type in an address like 'Amy's parents' list I can send is no longer a big e-mail to all members of my family in a single click. I'll take a note "no-no" of you Bird saying ' the close recipient of Amy isn't in the right format, to [email protected].» We cannot send this e-mail. ' (or something like that).

    Something like that didn't used to happen before late August 2014 or the beginning of September 2014.

    I even had a one-person e-mail fail this morning (08/09/14) because I tried typing a few letters and he knew to send the e-mail message, but it included these letters in the address. He made the speech out, for example, as 'NJ [email protected]' when I wanted it to be just "[email protected]". This kind of stupid things never before used.

    Can go back us to an earlier version of you Bird, to prevent this? Or a new version will stop it - I think - big bug?

    This has been reported as Bug #1060901. It is fixed in a next version of Thunderbird that is not yet available. Read further for more options back to a working configuration.

    Several other people have sent in the same request of support you, noting that it happened after they upgraded to version 31.1.

    The exact error message is: XXXX is not a valid e-mail address, because it is not the form user@host. You need to correct before sending the e-mail message.

    This happens in Thunderbird 31.1.0 when the description of your mailing list includes several words separated by spaces.

    Well that isn't ideal, these workaround solutions should allow you to use your mailing lists until a proper fix is implemented:

    • All by composing an email open the address book and select the list you want to send, to highlight all the names in the list and drag them to the To: box. This example uses your existing data without changing it.
    • Replace white "" between the words in the descriptions of these lists with an underscore "_". This requires modification of your descriptions of mailing list (s).
    • Upgrade to an earlier version and disable automatic updates (Windows)

    Go back to a previous version of Thunderbird and avoid the automatic updates

    In Thunderbird Windows updates are automatic by default. In order to avoid similar situations in the future, you could change that and decide to have a more cautious approach to updates.

    Before trying what anyone, make a backup of your Thunderbird profile.

    You can uninstall the current version of Thunderbird via Control Panel > programs and features and reinstall a previous version, download it from here:

    Click the type for your operating system. for example: If you use Windows select "win32", then select the language for example: en-GB British English = then download the .exe file

    You can customize the behavior of automatic updates, however, it is under Tools > Options > advanced > update.

    My suggestion would be to check the updates but let me choose whether to install them.especially if you depend on critical business e-mail / important or personal questions.

Maybe you are looking for

  • Satellite C850-1DJ restarts every 15 min after Win 8.1 and update drivers

    Log name: SystemSource: Microsoft-Windows-Kernel-PowerDate: 11/01/2013 18:42:40Event ID: 41Task category: (63)Level: criticalKey words: (2).User: SYSTEMComputer: chirimoya The system has rebooted without judgment properly first. Correctly this error

  • Time capsule will not recognize the backup from another mac

    Time machine will not recognize the backup from another mac

  • app and msn email ePrint

    I just bought a Photosmart 6520 new and was very excited about the features wireless and eprint.  I activated my email address successfully, but my problem is to be able to access my mail within the app. I spent hours trying to find a solution online

  • Tune-up for a Windows Xp computer app

    Original title: disorders puter dose anyone know a good (free) tune-up approx. pg i' really my computer messed up ev... Thank you

  • USB port is not HARD drive docking station

    I am using a USB docking station to retrieve data from a HDD to EIDE WD Caviar.  When I plug the engine up to the docking station with the installed drive in the usb port, the PC is not as he knows that something is connected to the port.  PC just do