Recover latest data from date

CREATE TABLE PRICE
(
  ITEM_NAME  VARCHAR2(40),
  RATE       NUMBER,
  EFF_FROM   DATE,
  EFF_TO     DATE
)


INSERT INTO PRICE(ITEM_NAME, RATE, EFF_FROM, EFF_TO) VALUES('ABC',21.5,'19-NOV-2008','26-NOV-2010');
INSERT INTO PRICE(ITEM_NAME, RATE, EFF_FROM, EFF_TO) VALUES('ABC',23,'27-NOV-2010','31-MAR-2012');

SELECT * FROM PRICE

For the item ABC there are tow different rates for different period.

How to write a query to get the rate of the latest period ? Kindly suggest ?
Sanjay

Hello

I made a mistake in the original message. Try what is today displayed:

SELECT     MAX (eff_to)
,     MIN (rate) KEEP (DENSE_RANK LAST ORDER BY eff_to)     AS last_rate
FROM     price
;

Another approach is:

WITH     got_r_num     AS
(
     SELECT     item_name, rate, eff_from, eff_to
     ,     RANK () OVER (ORDER BY eff_to DESC)     AS r_num
     FROM     price
--     WHERE     ...     -- IF YOU NEED ANY FILTERING, PUT IT HERE
)
SELECT     item_name, rate, eff_from, eff_to
FROM     got_r_num
WHERE     r_num     = 1
;

As you can see, it's a bit more coidng, but it is much more flexible. For example, it can easily show any number of columns in the row with the last eff_to, it can manage the links in different ways, and it can show you the latest rates of N (this is why it's called a Query Top - N ).

Tags: Database

Similar Questions

  • Windows XP does not start. Can I boot Windows from a disk so that I can recover the data?

    Windows XP does not start. Can I boot Windows from a disk so that I can recover the data? This should be a CD because it doesn't have a floppy disk on my laptop drive. It is maybe that my hard drive has begun to fail and therefore cannot locate XP startup files. I can not start using one of the other methods of starting for example. Safe mode. If I can recover the data, I can then reload Windows and check the surface of the disc etc etc. Thank you all for your comments. Steve

    Lately, I'm leaning toward the Hiren's BootCD you can download here:

    http://www.hirensbootcd.NET/

    On the left, click on download, scroll down, choose the most recent version

    The download link is a little hard to see.  It is at the bottom of the page, above the drop for older versions and looks like this (click this component to download the ZIP file):

    Direct HTTP mirror + Torrent, Torrent Magnet

    Click the "Live HTTP Mirror" link to start the download and save the ZIP file on your desktop of somewhere that you can remember.

    The ZIP file is large, so the download will take probably some time to complete.  Then unzip the download to extract theHirens.BootCD.ISO file that will be used to create your new bootable CD.

    Create a bootable CD. ISO file is not the same as simply copying the. File ISO onto a blank CD.  You must use software that includes how to burn a. ISO to a CD to create a bootable CD.

    File ZIP the Hiren is the file BurnToCD.cmd that you can double-click to launch it.  The BurnToCD.cmd will use the file BurnCDCC.exe to burn the. ISO file onto a blank CD using your existing CD burner.  You can also use your own burning software as long as your software is able to create a bootable CD. ISO file.  More modern burning programs can create a bootable CD. ISO image.  Create a CD from an ISO image bootable is not the same as just the file on a CD burning.

    If you need a simple and CD burning, this is a free software popular software:

    http://www.ImgBurn.com/

    Here are some instructions for ImgBurn:

    http://Forum.ImgBurn.com/index.php?showtopic=61

    It would be a good idea to test your new bootable CD on a computer running.

    You may need to adjust the computer BIOS settings to use the CD-ROM drive as the first device to boot instead of the hard drive.
    These adjustments are made before Windows tries to load.  If you miss it, you will need to restart the system again.

    When starting on the Hiren's CD, you will see a menu of options.  Choose Mini XP.

    It will appear while Windows is loading and you will be presented with a desktop computer that has the look and feel of the interface of Windows Explorer, you are already accustomed to using.  You will feel at home.

    Using the Mini XP, you can access the Internet, maneuver around your system, copy files, replace the files, run the scans for malware, etc.  There are dozens of free and useful tools included in the CD that can be used to repair your system, or copy files to another device such as a USB device or an external drive if drop in trying to repair your system.

    If you want to see if you can fix your system, describe what is happening when you try to start and to answer these questions:

    What is your system brand and model?

    What is your Version of XP and the Service Pack?

    Describe your current antivirus and software anti malware situation: McAfee, Norton, Spybot, AVG, Avira!, Defender, ZoneAlarm, PC Tools, MSE, Comodo, etc..

    You have a true bootable XP installation CD (it is not the same as any recovery CD provided with your system)?

  • BlackBerry smartphone how to recover lost data from blackberry phone?

    Hello, I deleted some photos on my Blackberry phone, how do I get back them? I have no backup!

    Jackrouslly wrote:

    What data recovery app will be working with me?  Please recommend some, thanks!

    If you use Blackberry Priv, you can try some android data recovery app, which you can find similar applications on Play store and google. I am currently using it, which has helped me recover deleted contacts and text messages. You can have a try: http://www.androidphonesoft.com/resources/recover-lost-contacts-from-android-phone.html

  • How to recover lost data from calendar

    I lost all calendar entries from before June 25 and use this computer in December 2012.   I suspect that it was when I upgraded to Windows 8.1?  How can I recover this data?

    The calendar application is just a "reader", although data shows is always stored online at http://calendar.live.com. This is so that if you buy a new computer (or drop/break/lose yours), you will lose any information: it's all about the Web site ready to synchronize again.

    So go to this link and you should find all your data.

  • Get the latest data of Variable shared before disconnecting from the network

    Hello.

    I use Shared - published network variables for my communication between two PC's. Each LV software will pass the data to another.

    Sometimes the wireless connection to become really bad and the network connection stops.

    I want to get the latest data. Currently my VI will show the value '0' on the variable shared data once the connection is cut.

    I tried using shift, but she registers the same results.

    Can someone show me how I can stay past data when the network connection is disconnected.

    Thank you very much.

    Kind regards

    Hello Fan, Ravens

    It works! Thank you very much.

    Kind regards

  • Could not initialize and I need to recover the data on the hard drive.

    Original title: computer MOM will not start and I need to recover the data on the hard drive.

    It's an old computer and I do not know what version of Windows it was running.  I guess I need a bootdisk of exploitation, but where can I download that?  Or would it be easier to pull and make a secondary drive in my computer that I just replaced?  It works under Windows XP.

    Hello

    If the old system does not start could be the hard drive. Put the hard drive in another computer as a 2nd drive and then access the files. If you use a computer XP, Vista or Windows 7, you should be able to access the files, unless the drive has failed.

    You can save your files by putting the drive in another computer as a 2nd drive (better) or a USB external drive case and then save up to removable media such as CD, DVD or other USB drives. Of course a real store of the computer or the manufacturer of your system can help to recover the files.

    Or you can use a boot Ubuntu CD to back up data. (This will not work if the hard disk is defective or other issues preventing the system from booting from the CD/DVD drive.)

    Use Ubuntu Live CD to backup files from your Windows computer dead
    http://www.howtogeek.com/HOWTO/Windows-Vista/use-Ubuntu-Live-CD-to-backup-files-from-your-dead-Windows-computer

    I hope this helps.
    --------------------------------------------------------------------------------------------
    Rob Brown - Microsoft MVP<- profile="" -="" windows="" and="" devices="" for="" it :="" bicycle="" -="" mark="" twain="" said="" it="">

  • flash drive crashed; Formatt required; any way I can recover the data?

    I downloaded a file to my USB key quickbooks.

    The first time that I saved the file to the flash drive errored out in the middle of recording.

    When I tried to access the file on the flash drive, I was told the drive needed to be formatted.

    Is it possible to recover the data on the flash drive?

    Thank you.

    Hi RexSweetwood,

    The problem that you are experiencing is very common, it is often caused by the pluging and unpluging the flash hard drive. In this case, you probably can't get your data from the flash drive, however, if the data in the flash player are very important, you can contact the manufacturer of your flash drive to ask if you can recover the data.

    In other words, in this case, you can easily get your fixed USB (the manufacturer can do it), but you probably cannot recover the data.

    Good luck to you.

    Gavin

  • I want to recover the data on the hard drive using a laptop as a hard drive.

    Original title: Using a laptop as a hard drive...

    On a MAC, I can plug my laptop into my office with a firewire port to access the hard drive on the laptop without the OS being ran on the laptop.  Windows Vista has such a thing?  If so, how do you go?  The hard drive on my Windows laptop fails and we want to try and recover the data, by hooking it to a desktop as shown above with the MACs.

    Thank you in advance!

    Hello

    "There is no way to access the hard drive when there is no operating system and if the hard drive is connected terribly."

    However, you can remove the hard drive from the laptop and connect it to the office with a case of hard disk that comes with the USB cable.

    Reference:

    Space to grow:
    http://Windows.Microsoft.com/en-us/Windows-Vista/room-to-grow-get-more-space-by-using-external-hard-disk-drives

  • How to recover my data

    2 months ago, I bought a laptop Vostro 3560. Windows 7 has been installed with HARD drive in AHCI mode.

    Today, I'm trying to install Windows 7 (64-bit) and with HARD drive changed the RST fashion. During the OS installation, it asks that the HARD disk driver. I downloaded the drivers SATA 2 from the DELL support site. If I choose a 64 bits, Windows 7 refuse to use it. So I tried the 32 bit one and it seems OK and Windows 7 is installed.

    But after log on Windows 7, it is surprising that all my data on an other readers (not on the system drive, but on the same disk) has changed some strange data!

    I doubt that it is because the 32 bit SATA driver. Because it contains import business data, I restart the system, change drive HARD in AHCI and reinstalled Windows 7 (64-bit) mode. In this mode, the SATA driver is not necessary, and Windows 7 installed successfully.

    This time before you connect to Windows 7, he invites me to check my data disc, I agree, and after about 1 minute during control, Windows 7 starts to delete some record! I wait about 20 seconds and then restart the computer before the end.

    This time I jump the control step drive and connect directly to Windows 7. Unfortunately this time Windows 7 seems lost all my data...

    I'll keep the running computer and use Windows Data Recovery to recover some data. He is busy running, appears with most of the names of files ok but most of the content are messy. I take care to save the recovered data to another mobile disk, without my original disk changing.

    What can I do more? Thanks in advance for your help.

    James ZHAO,

    Download and install Recuva

    Do a deep analysis. He must find most of the files and folders you're looking for. Programs and software must be installed manually.

    Rick

  • Is it possible to recover the data that you have saved a temporary profile?

    Hallo.
    I would like to know if I can recover data lost, which is very important.
    I work in a German Institute that uses windows 7 Enterprise. In order to use computers you log on with a user account.
    There are ten days, that I moved to a new computer. I have connected my user account and downloaded a file from the internet. This file was saved in the folder "downloads". Then, I worked on this file and saved the work every day in this same folder. I never stop the computer during these ten days, I just disconnected.
    This morning, I rebooted the computer for the installation of the updates of Windows, and when I reviewed my file, the full 'downloads' folder was empty. Aparently that this folder is not synchronized with my user account.
    If the information that I received is that Windows errased everything there wasn't in this folder all the time because it was a "temporary" account
    The team found an AutoSave file that is corrupted. Is there anything that can be done to recover this data?
    Please, such aid is very important to me. Thank you!

    [moved German forums]

    How do you know if you were using a temporary account?  If it's temporary, data are missing. But if the account was not temporary, you can find your files under the folder C:\Users.

  • How to recover the data file in Oralcle 10 g...? No backups and no newspaper archiving

    All,

    I need to recover the data file 2, which is for the undo tablespace and it is in the State to recover and I need to recover the data files now.

    But the bad news is we have no backup at all and we have no archive logs (log archiving is disabled in the database)...

    In this case how can I recover the data file...?


    SQL > select a.file #, b.SID, a.status from v$ datafile a, v$ tablespace b where a.ts #= b.ts #;

    FILE NAME STATUS NO.
    ---------- ------------------------------------------------------------------------------------------ -------
    1 /export/home/oracle/flexcube/product/10.2.0/db_1/oradata/bwfcc73/system01.dbf SYSTEM
    * RETRIEVE /export/home/oracle/logs/bw/undotbs01.dbf 2 *.
    3 /export/home/oracle/flexcube/product/10.2.0/db_1/oradata/bwfcc73/sysaux01.dbf online
    4 /export/home/oracle/datafiles/bw/bwfcc73.dbf online
    5 /export/home/oracle/datafiles/bw/bwfcc73_01.dbf online

    SQL > archive logs list;
    Database log mode no Archive Mode
    Automatic archival disabled
    Destination of archive USE_DB_RECOVERY_FILE_DEST
    Sequence of journal online oldest 4940
    Current log sequence 4942

    Hello

    First, you must open a ticket with oracle Support and explore the options

    You can use this note to fix:
    RECOVERY OF A LOST IN A [ID 1013221.6] UNDO TABLESPACE DATA FILE

    If you are unable to drop Undo tablespace as Undo Segment recovery must

    You can download the trace file following the opening of the ticket

    SQL>Alter session set tracefile_identifier='corrupt';
    
    SQL>Alter system dump undo header "";
    
    Go to udump
    
    ls -lrt *corrupt*
    
    Upload this trace file
    
    Also upload the alert log file
    

    Kind regards
    Levi Pereira

    Published by: Levi Pereira on November 29, 2011 13:58

  • Recover more data...

    Hello

    IM new to javascript, I would retrieve several data and fill in several areas.

    But I don't know javascript code for when only one data extraction.

    Application process:
    declare
    v_ename emp.ename%type;
    begin
    select ename
    into v_ename
    from emp
    where emp_id = :P1_EMPID;
    htp.prn(v_ename);
    exception when others then htp.prn('An error occurred retrieving the name');
    end;
    JavaScript:
    function get_ename(){
    var emp_id = document.getElementById('P1_EMPID').value;
    var get = new htmldb_Get(null,html_GetElement('pFlowId').value, 'APPLICATION_PROCESS=GET_ENAME’,0);
    get.add('P1_EMPID',emp_id);
    var gReturn = get.get();
    document.getElementById('P1_ENAME').value = gReturn;
    }
    The example above it recover data only ename...

    If I retrieve several data IE ename, * pay *, * date_of_birth * IE
    declare
    v_ename emp.ename%type;
    v_sal emp.ename%type;
    v_dob emp.ename%type;
    begin
    select ename,salary,dat_of_birth
    into v_ename,v_sal,v_dob
    from emp
    where emp_id = :P1_EMPID;
    htp.prn(v_ename);
    htp.prn(v_sal);
    htp.prn(v_dob);
    exception when others then htp.prn('An error occurred retrieving the name');
    end;
    so, what would be my javascript for above application process IE recover more data?
    pls can change the javascript above?


    Thank you and best regards,
    SKUD

    SKUD,
    This error is raised by the following line

    DBMS_ASSERT. SIMPLE_SQL_NAME (wwv_flow.g_x01)

    That function according to the documentation survey except in the case where the value passed is not in line with a certain pattern (see the doc for more information on this)

    If you just want to work, you can change it to

    P_ID: = wwv_flow.g_x01;

    and the page should work as you expect.

    You can modify the code to use the package DBMS_ASSERT, if necessary after having gone through the documentation.

  • How can I recover a data file if it drop without backup!

    Dear friends,

    I have a request.

    In oracle database 10g, I created a database of test name 'medium '. I created a tablespace "support_ts" here.
    In my absent mind, I deleted the data file that is associated with "support_ts" physically. Logically the tablespace information is in the database, but physically the data file is deleted.

    'SUPPORT' database has no backup (export and rman), also the database is in noarchivelog mode.

    Now, is it possible to recover or do I focely delete the tablespace for database information? While, in the next database startup search information tablespace "support_ts"?

    Hello

    Recover the data file is not possible without the backup of the data file.

    You can re-create the control file and the startup of the database.

    Steps to recrete the control file.

    1. change controlfile backup of database to trace in the "";
    2. open the control file and remove the entry from tablespace and datafile support partly noreset newspapers.
    3. connect sys as sysdba
    4 cancel immediately / closed stop
    5 startup nomount
    6. paste balls noreset controlfile content
    7. After you have created the mount controlfile and open the database.

    Kind regards
    Prasanna

  • get the latest dates

    Hello
    I have a simple question... .i do not know why I m brain dead today...

    I m trying to get the date limit for the id of each

    with test_data as(
    select '001'id, 'xyz'name, '1/1/2009'start_date from dual union all
    select '001',  'abc', '1/2/2099' from dual union all
    select '001',  'def', '1/3/2009' from dual union all
    select '001',  'ghi', '1/4/2009' from dual union all
    select '001',  'jkl', '1/5/2009' from dual 
    )
    
    The output i m looking for just one record with latest date
      with result as 
      (
         select '001',  'jkl', '1/5/2009' from dual  
       )
    
    i tried this 
    
     select id,name, greatest(start_date) from test_data
      group by id,name,start_date 
      
    It gives me output ...which i m not lookg for 
    
      with t as 
      (
         select '001',  'abc', '1/3/2009' from dual union all 
         select '001',  'ghi', '1/4/2009' from dual union all
         select '001',  'jkl', '1/5/2009' from dual 
       )select * from t
       
    I was wondering if we have any function in oracle PL/SQL to do this kind of things

    Any suggestion is greatly appreciated! Thanks much sio!

    Published by: user642297 on March 12, 2010 12:21
    SQL> with test_data as(
      2  select '001'id, 'xyz'name, '1/1/2009'start_date from dual union all
      3  select '001',  'abc', '1/2/2099' from dual union all
      4  select '001',  'def', '1/3/2009' from dual union all
      5  select '001',  'ghi', '1/4/2009' from dual union all
      6  select '001',  'jkl', '1/5/2009' from dual union all
      7  select '002',  'ghi', '1/4/2009' from dual
      8  )
      9  select id, max(start_date), max(name) keep (dense_rank first order by start_date desc)
     10  from test_data
     11  group by id;
    
    ID  MAX(STAR MAX
    --- -------- ---
    001 1/5/2009 jkl
    002 1/4/2009 ghi
    

    Max
    http://oracleitalia.WordPress.com

  • Another way to recover the data - query

    I tried the latest data for these type_idS: '306 ', '303', '304',' 305'

    Here's the query according to datatime. Other alternatives to get the same

    Select T.TYPE_ID, t.t_desc, T.CREATED_DATE in gen_comment t
    where
    (t.type_id, created_date) in
    (select dfd.type_id, max (dfd.created_date) in gen_comment Diabaté
    When type_id in ('306', '303', '304',' 305')
    Dfd.type_id group);


    gen_comment

    TYPE_ID created_date t_desc
    rere 303 13/05/2009-09:07:50
    Diabate 303 2009-05-13 10:14:24
    Wew 303 05/13/2009 10:20:51
    304 dsds 2009-05-13 10:20:51
    304 sds 13/05/2009 10:20:51
    sfef 305 13/05/2009 10:20:51
    305 European works councils 2009-05-13 10:20:51
    305 ewged 13/05/2009 10:20:51
    305 hghgg 13/05/2009 10:20:51
    Ferfer 306 13/05/2009 10:20:51
    306 dfdfbv 13/05/2009 10:20:51

    Thank you.

    Hello

    An alternative:

    SQL> select * from gen_comment;
    
       TYPE_ID T_DESC CREATED_DATE
    ---------- ------ ----------------------
           303 rere   05/13/2009 09:07:50 AM
           303 dfdf   05/13/2009 10:14:24 AM
           303 wew    05/13/2009 10:20:51 AM
           304 dsds   05/13/2009 10:20:51 AM
           304 sds    05/13/2009 10:20:51 AM
           305 sfef   05/13/2009 10:20:51 AM
           305 ewcs   05/13/2009 10:20:51 AM
           305 ewged  05/13/2009 10:20:51 AM
           305 hghgg  05/13/2009 10:20:51 AM
           306 ferfer 05/13/2009 10:20:51 AM
           306 dfdfbv 05/13/2009 10:20:51 AM
    
    11 rows selected.
    
    Elapsed: 00:00:00.01
    SQL> select type_id
      2  ,      t_desc
      3  ,      created_date
      4  from ( select   type_id
      5         ,        t_desc
      6         ,        created_date
      7         ,        max(created_date) over (partition by type_id) max_date
      8         from     gen_comment
      9         where    type_id in (306,303,304,305)  -- HOPE WE'RE NOT STORING NUMBERS AS STRINGS HERE?
     10       )
     11  where max_date = created_date;
    
       TYPE_ID T_DESC CREATED_DATE
    ---------- ------ ----------------------
           303 wew    05/13/2009 10:20:51 AM
           304 dsds   05/13/2009 10:20:51 AM
           304 sds    05/13/2009 10:20:51 AM
           305 sfef   05/13/2009 10:20:51 AM
           305 hghgg  05/13/2009 10:20:51 AM
           305 ewcs   05/13/2009 10:20:51 AM
           305 ewged  05/13/2009 10:20:51 AM
           306 ferfer 05/13/2009 10:20:51 AM
           306 dfdfbv 05/13/2009 10:20:51 AM
    
    9 rows selected.
    
    Elapsed: 00:00:00.09
    SQL> -- your query
    SQL> select t.type_id,t.t_desc,t.created_date
      2  from gen_comment t
      3  where (t.type_id,created_date) in ( select dfd.type_id,max(dfd.created_date)
      4                                      from gen_comment dfd
      5                                      where type_id in ('306','303','304','305')
      6                                      group by dfd.type_id);
    
       TYPE_ID T_DESC CREATED_DATE
    ---------- ------ ----------------------
           303 wew    05/13/2009 10:20:51 AM
           305 hghgg  05/13/2009 10:20:51 AM
           305 ewged  05/13/2009 10:20:51 AM
           305 ewcs   05/13/2009 10:20:51 AM
           305 sfef   05/13/2009 10:20:51 AM
           306 dfdfbv 05/13/2009 10:20:51 AM
           306 ferfer 05/13/2009 10:20:51 AM
           304 sds    05/13/2009 10:20:51 AM
           304 dsds   05/13/2009 10:20:51 AM
    
    9 rows selected.
    
    Elapsed: 00:00:00.11
    

Maybe you are looking for

  • Blade tool precision is off, not cut on the read head

    When you try to cut (using the CMD + B tool or a blade to cut the read head) it's offset Cup at the beginning of a block of gray 1 second at the place where the playhead is actually. How can I get the tool of the blade to cut on the head rather than

  • How do I delete photos from my phone but keep them in my Mac?

    Hello I have my phone set up to use iCloud for photo only stream. When in range, I can see the latest pictures in my Mac photo stream. I want to be able to save some of these images immediately in my iPhoto and delete them from my phone. How to achie

  • Satellite L50T-A196 - how to access the BIOS

    Hello I just bought a new laptop Toshiba Satellite L50T-A196 and it worked very well and the great until recently. I tried to reformat my computer because it got crashed.I was able to reformat my computer very well in previous years.So far, I've refo

  • The fires of speaker on Satellite P100-429

    Is it possible to turn off the blue lights under the harman kardon speakers on this laptop? It seems silly that a multimedia notebook designed to play DVDs has these lights distract when you want to watch a DVD in the night, and the battery life is (

  • Is there a manual? Impossible to find

    My partner has FaceTime on Mac Montain lion, I have FaceTime on iPhone, if my partner is in trouble and because I can't find a manual I can't help him. Is there a manual? ~ k.