Getting the latest area for each case

dear all;
I have a table with the following info below
create table tmp_a
       idv number(30),
       personid number(30),
       Area varchar2(200),
       dateadded date,
       is_close number(2)
insert into tmp_a
  (idv, personid, area, dateadded, is_close)
values
  (1, 10001, 'ZONE_A', sysdate, 1);
insert into tmp_a
  (idv, personid, area, dateadded, is_close)
values
  (2, 10002, 'ZONE_B', sysdate, 0);
insert into tmp_a
  (idv, personid, area, dateadded, is_close)
values
  (3, 10003, 'ZONE_A', sysdate, 0);
insert into tmp_a
  (idv, personid, area, dateadded, is_close)
values
  (4, 10003, 'ZONE_A', sysdate, 0);
  Now I would like to get this below
idv   Personid   Area        Dateadded                           Is_clode
4       10003   Zone_A     3/3/2011 1:00:37PM               0
2       10002   Zone_B     3/3/2011 12:17;14PM              0the output is based on the fact, if there are duplicates associated with the area, the query should pick the latest one...In this case, the latest one for zone_A is idv 4.
kindly note, idv is a primary key. How do I go about doing that? All help is appreciated. Thank you.

Hi,
ROW_NUMBER returns a unique number for every row. If you have n rows, it will return the integers 1 through n, without skipping or duplicating any numbers, so you can be confident it will return the number 1 on exactly 1 row.
ROW_NUMBER (PARTITION BY area ...)     means that a separate set of integers, each starting with 1, will be returned for each distinct value of area.
ROW_NUMBER (PARTITION BY area ORDER BY idv DESC)     means that the numbers will be assigned in DESCending order by idv. The row with the highest idv for each area will be the row for which ROW_NUMBER returns 1.
The LAST function, as demonstrated by Solomon, is a good thing to have in your toolbox, but you have to code a somewhat complicated expression for each column (except the GROUP BY column, and the column that determines the order). When you need to pick an entire row, I find it easier to use ROW_NUMBER.
Also, ROW_NUMBER can easily be adapted if your needs change. Where I work, people are always saying things like "Remember that query you wrote for me, that returns the latest row fro each area? Can you make it return the latest 5 rows?" or "It truns out idv isn't unique. Can you make it return all the rows with the highest idv?" It's easy to change the ROW_NUMBER solution to do things like that.

Similar Messages

  • Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at http:// (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Is this a webpage that contains a link to a flv file? Please post a link to the page and tell us which link(s) are the problem flv files or else post a link to the .flv file itself.
    Alternately, click on one of the sample FLV File links on this page and tell us exactly what happens:
    http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html
    It might also help if you post the exact error message, including the path to the flv file.
    '''Note:'''
    Depending on how you have Firefox set up, clicking on a FLV File link will either save the FLV file to your computer or Firefox may open it automatically in an external application right after downloading (Firefox may ask you first). Firefox itself can't play FLV files so you need a "helper" application (or a plugin for flv files, if ther is one. You can see if Firefox is already set up to download or open FLV files by going to Firefox Preferences and looking in the Applications list. Find the FLV file type in the list and, if the action is "Open with", it should show the application that can play FLV files (e.g., VLC Media Player or Perian). See [[Managing filetypes]] for more information.

  • Getting the first row for each group

    Hi Everyone,
    I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
    For example ...
    client flight startairport destairport stops
    A fl123 LGW BKK 2
    A fl124 LHR BKK 5
    B fl432 LGW XYZ 7
    B fl432 MAN ABC 8
    .... etc.
    I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
    I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
    So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
    Can anyone help me with this? I'm sure that there must be a command to handle this.
    Regards and any thanks,
    Alan Searle
    Cologne, Germany

    Something like this:
    select *
    from (
       select table1.*
       row_number() over (partition by col1, col2 order by col3, col4) rn
       from table1
    where rn = 1In the "partition by" clause you place what you normally would "group by".
    In the "order by" clause you define which will have row_number = 1.
    Edit:
    PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
    Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM

  • What is the latest update available for Mac OSX 10.5.8 that will allow me to get the latest update for iTunes.  I really need to update my iPhone and CAN'T!!  GRRRR!!!

    What is the latest update available for Mac OSX 10.5.8 that will allow me to get the latest update for iTunes.  I really need to update my iPhone and CAN'T!!  GRRRR!!!

    Minimally you need Snow Leopard or greater:
    Upgrade Paths to Snow Leopard, Lion, and/or Mountain Lion
    You can upgrade to Mountain Lion from Lion or directly from Snow Leopard. Mountain Lion can be downloaded from the Mac App Store for $19.99. To access the App Store you must have Snow Leopard 10.6.6 or later installed.
    Upgrading to Snow Leopard
    You can purchase Snow Leopard through the Apple Store: Mac OS X 10.6 Snow Leopard — Apple Store (U.S.). The price is $19.99 plus tax. You will be sent physical media by mail after placing your order.
    After you install Snow Leopard you will have to download and install the Mac OS X 10.6.8 Update Combo v1.1 to update Snow Leopard to 10.6.8 and give you access to the App Store. Access to the App Store enables you to download Mountain Lion if your computer meets the requirements.
         Snow Leopard General Requirements
           1. Mac computer with an Intel processor
           2. 1GB of memory
           3. 5GB of available disk space
           4. DVD drive for installation
           5. Some features require a compatible Internet service provider;
               fees may apply.
           6. Some features require Apple’s iCloud services; fees and
               terms apply.
    Upgrading to Lion
    If your computer does not meet the requirements to install Mountain Lion, it may still meet the requirements to install Lion.
    You can purchase Lion by contacting Customer Service: Contacting Apple for support and service — this includes international calling numbers. The cost is $19.99 (as it was before) plus tax.  It's a download. You will get an email containing a redemption code that you then use at the Mac App Store to download Lion. Save a copy of that installer to your Downloads folder because the installer deletes itself at the end of the installation.
         Lion System Requirements
           1. Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7,
               or Xeon processor
           2. 2GB of memory
           3. OS X v10.6.6 or later (v10.6.8 recommended)
           4. 7GB of available space
           5. Some features require an Apple ID; terms apply.
    Upgrading to Mountain Lion
    To upgrade to Mountain Lion you must have Snow Leopard 10.6.8 or Lion installed. Purchase and download Mountain Lion from the App Store. Sign in using your Apple ID. Mountain Lion is $19.99 plus tax. The file is quite large, over 4 GBs, so allow some time to download. It would be preferable to use Ethernet because it is nearly four times faster than wireless.
         OS X Mountain Lion — System Requirements
           Macs that can be upgraded to OS X Mountain Lion
             1. iMac (Mid 2007 or newer) — Model Identifier 7,1 or later
             2. MacBook (Late 2008 Aluminum, or Early 2009 or newer) —
                 Model Identifier 5,1 or later
             3. MacBook Pro (Mid/Late 2007 or newer) — Model Identifier 3,1 or later
             4. MacBook Air (Late 2008 or newer) — Model Identifier 2,1 or later
             5. Mac mini (Early 2009 or newer) — Model Identifier 3,1 or later
             6. Mac Pro (Early 2008 or newer) — Model Identifier 3,1 or later
             7. Xserve (Early 2009) — Model Identifier 3,1 or later
    To find the model identifier open System Profiler in the Utilities folder. It's displayed in the panel on the right.
    Are my applications compatible?
             See App Compatibility Table — RoaringApps.
         For a complete How-To introduction from Apple see Upgrade to OS X Mountain Lion.

  • How to get the depreciation areas for an asset in particular period

    Hi frndz,
      how to get the depreciation areas for an asset in a particular period for writeup or manual depreciation method.
    Thanks and regards.
    Harisumanth.Ch

    Try table ANLB, then read ANLC.
    Regards.

  • How can I get the latest firmware for a WRT54GS 7.2? I ac...

    How can I get the latest firmware for a WRT54GS 7.2? I accidentally downgraded to 7.2.05, and it came with 7.2.06.

    Thank you! I tried that link, it came as a page not found on the Linksys site. I went to the UK version of the Linksys site, and they don't list the 7.2 version of the router. They only go up to 6.0.

  • How to get the latest update for the phone?

    hey does anyone know how to get the latest upgrade for my phone? 3230 nokia

    http://www.nokia.co.uk/nokia/0,,58162,00.html
    Gadget
    Remember to mark all correctly answered questions as Solved. A forum is only as great as the sum of its parts, together we will prevail.

  • How to get the time interveral for each status of worklow (wating,Inprocess

    Hi Friends,
    I have requreiemnt to get the time interval for each status of workflow.
    ex.
                                                                     status
    workflow id  | startd date | enddate       | waiting | Inprocessing|Error|......
    1026            10.10.2008  25.10.2008        1hr      1hr 30 min    2 hr
    Please do give me idea how to get the time stam of each status of workflow.
    Thanks,
    D.prabhu

    Hi,
    I think the following tables would be helpful to you:-
    SWW_CONT     Container Contents for Work Item Data Container
    SWW_CONTOB     "Container Cont. for Work Item Data Container (Only Objects)"     
    SWWLOGHIST     History of a work item     
    SWWORGTASK     Assignment of WIs to Org.Units and Tasks     
    SWWUSERWI      Current Work Items Assigned to a User     
    SWWWIHEAD     Header Table for all Work Item Types
    Hope it Helps!
    Regards,
    Kanika

  • Grab a list of the latest note for each job when/if they start with set text

    How would I look only to the latest [01-JobComment].[Creation_Date] where [01-JobComment].[text] starts with the text "AB001:" for each [05-Job].[Job_ID]?
    SELECT [05-Job].Job, [01-JobComment].[CREATION_DATE], Mid([01-JobComment].[TEXT],1,6) AS AB001, [05-Job].Name, [05-Job].Owner, [05-Job].Type, [01-JobComment].CREATED_BY, [01-JobComment].CREATED_BY, [05-Job].Status, [05-Job].Owner
    FROM [05-Job] INNER JOIN [01-JobComment] ON [05-Job].Job = [01-JobComment].JOB_ID
    WHERE ((([01-JobComment].[CREATION_DATE])>[05-Job].[AsBuiltProof]) AND ((Mid([01-JobComment].[TEXT],1,6))="AB001:"))
    ORDER BY [01-JobComment].[CREATION_DATE];

    I'm not sure this is what you want:
    SELECT [05-Job].Job, (SELECT Max(T.CREATION_DATE) FROM [01-JobComment] AS T WHERE T.JOB_ID=[01-JobComment].JOB_ID AND Left(T.[text],6)='AB001:') AS CreationDate, Left([01-JobComment].[TEXT],6) AS AB001, [05-Job].Name, [05-Job].Owner, [05-Job].Type, [01-JobComment].CREATED_BY,
    [05-Job].Status
    FROM [05-Job] INNER JOIN [01-JobComment] ON [05-Job].Job = [01-JobComment].JOB_ID
    WHERE [01-JobComment].[CREATION_DATE]>[05-Job].[AsBuiltProof] AND Left([01-JobComment].[TEXT],6)="AB001:"
    ORDER BY [01-JobComment].[CREATION_DATE];
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Find out and get the bit value for each pixel in image

    i use 16bit image. the image is 200x200 pixels. i need to know what is
    the bit value for each pixel. example(0111111011111101).
    where i can see the bit value output. if somebody got the example surce code please send it to me.coz i need the bit value to find out how many RGB color that use in the image. thanks for ur help.

    How many logins do you have???

  • Why can't I get the text labels for each app to go away? I only see 9 app buttons now; used to see 30 or 40

    Text labels started showing up next to my app buttons going across toolbar. Because the names are fairly long (I don't need them per se); I can now only see about 10 buttons. I made sure the the box in the toolbar preferences menu which says "show text labels for each app." was unchecked. I even tried checking it, then unchecking it.
    I can't get the labels to go away. I used to be able to see and therefore USE EASILY about 30 -40 app buttons. I just downloaded the latest update to firefox 8.

    I am having something similar going on and can't sort out what it is doing:
    ldiffs:
    dn: automountMapName=auto_master,dc=example,dc=edu
    objectClass: top
    objectClass: automountMap
    automountMapName: auto_master
    dn: automountKey=/foo,automountMapName=auto_master,ou=Mounts,dc=soe,dc=ucsc,
    dc=edu
    objectClass: automount
    automountKey: /foo
    automountInformation: auto.foo,dc=example,dc=edu -rw,resvport,
    hard,intr,nosuid,tcp
    Second one:
    dn: automountMapName=auto.foo,dc=example,dc=edu
    objectClass: top
    objectClass: automountMap
    automountMapName: auto.foo
    dn: automountKey=tstaff,automountMapName=auto.foo,dc=example,dc=edu
    objectClass: top
    objectClass: automount
    automountInformation: fileserver:/export/foo/tstaff
    automountKey: tstaff
    9/25/09 11:45:25 AM com.apple.automountd[1101] t0xb0289000 name=tstaff[] map=auto.foo,dc=example,dc=edu opts=rw,resvport,hard,intr,nosuid,tcp path=/foo direct=0
    9/25/09 11:45:25 AM com.apple.automountd[1101] t0xb0289000 getmapent_ds called
    9/25/09 11:45:25 AM com.apple.automountd[1101] t0xb0289000 getmapent_ds: key=[ tstaff ]
    9/25/09 11:45:25 AM com.apple.automountd[1101] t0xb0289000 ds_match called
    9/25/09 11:45:25 AM com.apple.automountd[1101] t0xb0289000 ds_match: key =[ tstaff ]
    9/25/09 11:45:25 AM com.apple.automountd[1101] t0xb0289000 ds_match: Searching for tstaff,automountMapName=auto.foo,dc=example,dc=edu
    9/25/09 11:45:25 AM automountd[1101] ds_search failed
    exiting ...
    It seems like it can't find the trigger point tstaff. It is looking for:
    ds_match: Searching for tstaff,automountMapName=auto.foo,dc=example,dc=edu
    which isn't what the DN is in ldap:
    Distinguished Name: automountKey=tstaff,automountMapName=auto.foo,dc=example,dc=edu
    any thoughts?
    regards,
    Derek

  • Help needed with particle analysis (getting the pixel area of each particle)

    Hello,
    I am using a camera vision system to capture particles which works fine.
    I am using particle analysis tool to get the number of particles and it also gives particle report.
    I want the area of each particle HOWEVER the problem is that currently it does it only for 3 or 4 particles which is not good, and the number of particles can vary in each frame.
    also please it currently gives pixel measurements can i change this to mm cm?
    i have attached the vi so pls help
    thank you
    Attachments:
    BarleyBreadver2.vi ‏121 KB

    hi,
    sorry my mistake - it sees all the particles but the particle analysis only gives the area of seeds in the frame. they should bea way to store the previous particle area.
    it will be clear what i am trying to do when you open the vi. i simply want the area of all the particles that pass through the camera system and put them in their appropriate size range.
    for example all the particles from 200-400 pixels. the final value can be shown in a table or just a variable.
    thankyou 

  • How to get the latest firmware for BT Home Hub-3 &...

    I have had this new BT Home Hub3 activated last night. 
    To get connected wireless to my Mac Book Air and iPod Touch, I had to refresh the Wireless Channel in my BT Home Hub settings. The Hub has selected the Channel 11 automatically that works well for my home wireless connection.
    This morning, my Home Hub has reverted back to Channel 6 and my wireless would not work. I had to go back to the settings in the Home Hub-3 to "Refresh" to select the best Channel and it has chosen Channel 11 again and all works well.
    My question is how could I get the Home Hub-3 to remember the selected channel without me in the morning to refresh the setting on a daily basis?[I have tried by selecting the "Apply" and a green circle with a tick to denote that the change had taken place]
    Home Hub-3 current firmware Version 4.7.5.1.83.8.45 [Type A] and I noticed a new one available and How could I update mine to the latest?
    Regards
    Solved!
    Go to Solution.

    if you select advance settings and go back to the wireless page, you will be able to see channel selection, likely to be on Automatic (smart wireless); here you can manually select channel 11 and it will stay there.
    Check your exchange or major service outagesIf someone has given a helpful answer, please click on their Ratings star on the left-hand side. ***

  • Getting the max count for each group

    Hi, I am a newbie and working on a project for school. I have been working this problem for a couple of days and made a bit of progress.
    I have two tables, student and enroll for a college database. I need to show the students who have the most enrollments in each major. So far, I have:
    WITH COUNT_Q AS
    SELECT B.SSN, B.MAJOR, COUNT (A.CLASS_NO) AS COUNTCLASS
    FROM ENROLL A, STUDENT B
    WHERE A.SSN = B.SSN
    GROUP BY B.SSN, B.MAJOR
    SELECT MAX(COUNTCLASS), MAJOR
    FROM COUNT_Q
    GROUP BY MAJOR
    I am getting the correct results but need to show the SSN and Major of the studens. When I add in the SSN and Major, like below, I get back too many records.
    WITH COUNT_Q AS
    SELECT B.NAME, B.SSN, B.MAJOR, COUNT(A.SSN) AS COUNTCLASS
    FROM ENROLL A, STUDENT B
    WHERE A.SSN = B.SSN
    GROUP BY B.NAME, B.SSN, B.MAJOR
    SELECT *
    FROM COUNT_Q
    WHERE (COUNTCLASS) IN (SELECT MAX(COUNTCLASS)
    FROM COUNT_Q
    GROUP BY MAJOR
    Can someone help point me in the right direction?

    SELECT  B.NAME,
            B.SSN,
            B.MAJOR
      FROM  (
             SELECT  B.NAME,
                     B.SSN,
                     B.MAJOR,
                     COUNT(A.CLASS_NO) SSN_MAJOR_COUNTCLASS
                     DENSE_RANK() OVER(PARTITION BY MAJOR ORDER BY COUNT(A.CLASS_NO) DESC) RNK
               FROM  ENROLL A,
                     STUDENT B
               WHERE A.SSN = B.SSN
               GROUP BY B.NAME,
                        B.SSN,
                        B.MAJOR
      WHERE RNK = 1
    /SY.
    Edited by: Solomon Yakobson on Mar 27, 2011 6:53 PM

  • Getting the "latest" compressor for FCS1

    What is the latest version of Compressor that can be used with FCS1? My FCS comes with compressor 2.0; I can install 2.0.1; the qmaster-died-no-background-process error persists.
    Is Compressor 2.1 available, and if so what software update provides that? And what about that Apple page saying nothing <v2.3 works with Leopard?
    I am going to try overwriting my installation with Pacifist but suspect I will (again - or is 3rd time?) wipe the disk and re-reinstall Leopard and FCS and try yet again.
    That, or go to Tiger for the next 6 months.
    Thanks for any suggestions.
    Brian

    According to the Compressor Support page, the highest version for Compressor 2.0 is 2.0.1.
    When Apple started transitioning to Intel, they introduced a Crossgrade program which was a paid upgrade to Final Cut Studio 1.1 (FCP 5.1, Compressor 2.1, etc.). The Crossgrade program was extended a few times and lasted about 15-18 months. It was discontinued about a year ago, shortly before the release of Final Cut Studio 2.

Maybe you are looking for

  • FI-AA: Unable to settle costs off of AUC

    In Depreciation area 01 (Book Depreciation), planned/posted values were recorded on an AUC via settlement from WBS Elements during FY 2006. In Depreciation area 80 (Insurance Values), planned/posted values were recorded on an AUC via settlement from

  • MySpace eMail Virus?

    Someone said the eMail sent to them via MySpace eMail using the Blackberry MySpace application (I'm also sending this question to MySpace) contained a virus. How does one send a PC virus thru MySpace from a cellphone? If this is even possible ... and

  • About inter-relation b/w MM,PP,FICO and SD module

    Hi to all Plz describe me interrelation b/w MM-PP-SD and Fico module . If possible send me work-flow of these modules which is required to know for an ABAPER. Also tell me how a n ABAPER interact with a functional consultant . Thanks & Regards Anubha

  • Lost all my agents!

    Yesterday morning av ~0800 all my agents suddenly lost contact with my management server. The error message on the agent is:  The OpsMgr Connector connected to XXXX, but the connection was closed immediately after authentication occurred.  The most l

  • My iphone 3gs has been stolen, is there a way to have it jammed next time they plug it in to a computer, with the serial number. or can l track it some way...

    is there a way, that l can jam or locate a stolen 3gs iphone with the serial number. or is there another way, so it jams when connects to the internet.