Compare Dates and select the max date ?

Hello,
I am trying to write a script and will compare the dates in " eff_startdt" and give me the lastest date at the outcome.
I have data that some service locations have more than one contract date and I need to get the latest dated conract dates to work on the data but I tried many things I am always getting errors. When I run the script below I get " missing expression" error. I dont' see anything missing.
also somehow Max() is keep giving me errors when I do something like [  ON service_locs = vmeterid WHERE SERVICE_LOCS = SERVICE_LOCS AND EFF_STARTDT = MAX(EFF_STARTDT)  ]
Can someone pls give me advice on this. Thanks
SELECT DISTINCT Broker, customer_name, service_locs, fee_kwh, qtr_monthly, eff_startdt, eff_enddt
FROM VMETER
INNER JOIN BROKER_DATA
ON service_locs = vmeterid WHERE SERVICE_LOCS = SERVICE_LOCS AND (SELECT MAX(EFF_STARTDT) FROM VMETER)
-----------------------------------------------------------

Hi,
I will try to explain on my example. I have got a table:
DESC SOLD_ITEMS;
Name                                    Value NULL? Type
COMPONENT                                          VARCHAR2(255)
SUBCOMPONENT                                       VARCHAR2(255)
YEAR                                               NUMBER(4)
MONTH                                              NUMBER(2)
DAY                                                NUMBER(2)
DEFECTS                                            NUMBER(10)
DESCRIPTION                                        VARCHAR2(200)
SALE_DATE                                          DATE
COMP_ID                                            NUMBERI have insert example data into my table:
select component, subcomponent, sale_date,comp_id
  2  from sold_items;
COMPONENT       SUBCOMPONENT    SALE_DAT    COMP_ID                            
graph           bar             06/04/03          1                            
graph           bar             06/04/01          2                            
search          user search     06/04/02          3                            
search          user search     06/04/01          4                            
search          product search  06/03/20          5                            
search          product search  06/03/16          6                            
graph           bar             06/05/01          7                            
graph           bar             06/05/02          8                            
graph           bar             06/05/02          9
As you can see there are a few components and subcomponents duplicated with different date and comp_id value.
I want to get component and subcomponent combination with latest date.
SELECT COMPONENT, SUBCOMPONENT, MAX(SALE_DATE)
  2  FROM SOLD_ITEMS
  3* GROUP BY COMPONENT, SUBCOMPONENT;
Efect:
COMPONENT       SUBCOMPONENT    MAX(SALE                                       
graph           bar             06/05/02                                       
search          user search     06/04/02                                       
search          product search  06/03/20
For your purpose I will do it using join and subquery. Maybe it will help you resolve your problem:
SELECT COMPONENT, SUBCOMPONENT, SALE_DATE, RANK
  2  FROM (SELECT T1.COMPONENT, T1.SUBCOMPONENT, T2.SALE_DATE,
  3          ROW_NUMBER() OVER (PARTITION BY T1.COMPONENT, T2.SUBCOMPONENT ORDER BY T2.SALE_DATE DESC) AS ROW
  4          FROM SOLD_ITEMS T1, SOLD_ITEMS T2
  5          WHERE T1.COMP_ID = T2.COMP_ID)
  6* WHERE ROW = 1;
I joined the same table but it act as two different tables inside subquery. It will group values (partition by statement) and order result descending using t2.sale_date column. As you can see columns are returned from both tables. If you would like to add some conditions, you can do it after WHERE ROW=1 code.
Results:
COMPONENT       SUBCOMPONENT    SALE_DAT       RANK                            
graph           bar             06/05/02          1                            
search          product search  06/03/20          1                            
search          user search     06/04/02          1Hope this help you
Peter D.

Similar Messages

  • 2 time zones during inserting and selecting the data.

    we have applied DST patch and DST JAVA patch sucessfuly on oracle 10.1.0.3 version database . After that we have problem
    It was noticed that it failing for the following 2 time zones during inserting and selecting the data.
    MST7
    HST10
    Please help me to solve this

    Try MetaLink. Lots of hits on ORA-1882.
    Specifically, Note 414590.1 "Time Zone IDs for 7 Time Zones Changed in Time Zone Files Version 3 and Higher, Possible ORA-1882 After Upgrade" sounds promising.
    -Mark

  • I need to show grouped id and only the max order value for each unique id

    select distinct 
    Table1.id,
    Table1.id +' - '+ Table1.VisitNumber +' : '+ Table1.Priority as UidVisitKey,
    Table1.VisitNumber,
    DATEDIFF(d, [dob],[Visite_dte])/365.25 as Age_On_Visit,
    Table1.Priority,
    Table1.OrderOfVisit,
    Table1.OrderOfVisit + ' - ' + Table1.Notes AS VisitNote, 
    Table1.Visitor_FName,
    Table1.Visitor_SName,
    Table2.dob,
    Table2.sex,
    Table1.Visit_dte,
    into #Temp1
    FROM         Table1 INNER JOIN
                Table2 ON Table1.id = Table2.id
    WHERE Table1.LeaveDate IS NOT NULL 
    and Table1.LeaveDate  between DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)) 
    and DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))) 
    select #Temp1.id, max(#Temp1.[OrderOfVisit]), #Temp1.VisitNote 
    from #Temp1
    group by #Temp1.id, #Temp1.OrderOfVisit, #Temp1.[VisitNote]
    ORDER BY #Temp1.id
    drop table #Temp1
    ---I need to show grouped id and only the max OrderOfVisit for each unique id, and the VisitNote for each OrderOfVisit
    ----------------need help-------------

    Sounds like this
    select distinct
    Table1.id,
    Table1.id +' - '+ Table1.VisitNumber +' : '+ Table1.Priority as UidVisitKey,
    Table1.VisitNumber,
    DATEDIFF(d, [dob],[Visite_dte])/365.25 as Age_On_Visit,
    Table1.Priority,
    Table1.OrderOfVisit,
    Table1.OrderOfVisit + ' - ' + Table1.Notes AS VisitNote,
    Table1.Visitor_FName,
    Table1.Visitor_SName,
    Table2.dob,
    Table2.sex,
    Table1.Visit_dte,
    into #Temp1
    FROM Table1 INNER JOIN
    Table2 ON Table1.id = Table2.id
    WHERE Table1.LeaveDate IS NOT NULL
    and Table1.LeaveDate between DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))
    and DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)))
    select id,OrderOfVisit,VisitNote
    from
    select #Temp1.id, #Temp1.[OrderOfVisit], #Temp1.VisitNote,ROW_NUMBER() OVER (PARTITION BY #Temp1.id ORDER BY #Temp1.[OrderOfVisit] DESC) AS Seq
    from #Temp1
    )t
    WHERE Seq = 1
    ORDER BY id
    drop table #Temp1
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • After aborted rebuild in Mail: I can see and select the message in the center pane and when I click on it to display, I get "Loading" text, but nothing comes up

    I have searched quite a bit to find a resolution to this problem, with no success. Any help would be appreciated.
    I decided to rebuild my inboxes by following this advice: http://support.apple.com/kb/PH11704. The rebuild took several hours and at 96% (4 minutes remaining apparently), the indexing froze (that is, after 8 hours, the message was still telling me "4 minutes left"). I forced quit mail, restored the previous Envelope files from the trash, and everything seemed fine.
    However, since this failed attempt, I can see and select the message in the center pane and when I click on it to display, I get "Loading" text, but nothing comes up. All messages in my various inboxes have the reloading problem, EXCEPT messages that I downloaded since the aborted rebuild (in other words, there are about 40 messages that I downloaded since I tried the rebuild and I have no problem with these). The other 70,000 messages however wont load, even though I can see them in the centre pane and spotlight has no problem finding them and showing me their contents (when I hover the mouse over the message). When I click on the message in spotlight, mail opens and the loading problem re-occurs.
    Since then, based on various suggestions I found for similar issues, I have used Disk Utility to verify and repair permissions and the drive. I used Onix to rebuild the Mail index (that only took about a minute - I am not sure how to interpret this when compared to the hours the rebuild took with Mail). No joy, I still have the same problem. I even restored one of my inboxes via Time Machine and the same issue with loading continues.
    I am using ML 10.8.2. I have a combination of IMAP accounts (work) and POP accounts (personal). The issue of loading occurs irrespective of the account.
    I am baffled and am now considering migrating to either Thunderbird or Postbox 3 to try and solve my problem. I prefer to stay with Mail. I should note also that I am using MailTags with Mail (http://www.indev.ca/MailTags.html), although I have not used any of the features. I upgraded to ML from SL about 2 weeks ago. It was very smooth and there appear to be no issues (not sure how helpful this is and probably not at all related to this issue).
    Any suggestions much appreciated!

    Maybe these will help:
    https://discussions.apple.com/message/17677533#17677533
    https://discussions.apple.com/message/18324129#18324129
    https://discussions.apple.com/message/18203126#18203126

  • How to select the max rowid from a subquery with group by

    Hi Gurus,
    Kindly help how to fix the following query because I'm getting Oracle error:ORA-01446.
    select * from edy_raw_data a
    where rowid in ( select max(rowid) from(
    select email,max(date_updated) from edy_raw_data b
    where b.email=a.email
    group by email ))
    The query select the max rowid from a sub query with group by.
    Thanks in Advance.
    Benjie

    Why do you need to compare with rowid?
    Wouldn't this suffice?
    select * from edy_raw_data a
    where (email,date_updated) = (select email, max(date_updated) from edy_raw_data b
                        where b.email=a.email
                        group by b.email ))* Note: untested

  • I have LR 5.  When I'm in the book module and select the option to "Send Book to Blurb" i get an error message saying "The file does not have a program associated with it...."  How do I fix this?

    I have LR 5.  When I'm in the book module and select the option to "Send Book to Blurb" i get an error message saying "The file does not have a program associated with it for performing this action.  Please install a program, or if one is already installed, create an association in the Default Programs control panel."
    How do I fix this?

    Try the following user tip:
    "There is a problem with this Windows Installer package ..." error messages when installing iTunes for Windows

  • HI. I have itunes 10.6.1.7. When I goto movies i am not able to add and when I click on add file to library and select the file and add its not getting added. When i goto Library it says  that movies I add are in library.Which I cant add

    HI. I have itunes 10.6.1.7. When I goto movies i am not able to add and when I click on add file to library and select the file and add its not getting added. When i goto Library it says "feature films and home movies you add to itunes appear in movies in your iTunes library. To play a movie, just double click it". And below are two options for Downloading movies from store and rent movies. Please help.

    I get the exactly the same problem with win 7, i rang apple support who suggested i try another machine/or create another account on my machine???? why should i, stupid ipad 3rd gen is now sitting here un syncable, apple support ....tut tut very poor support, its a shame im out of the 7 day period otherwise this ipad would be going straight back, older versions of itunes worked fine, some one must know a fix for this??

  • HT201269 I'm trying to set up my new iPhone using iCloud - I entered my apple ID and password and selected the backup to restore from but the next page asks me to enter a password for a DIFFERENT apple ID

    I'm trying to set up my new iPhone using iCloud - I entered my apple ID and password and selected the backup to restore from but the next page asks me to enter a password for a DIFFERENT apple ID

    What different Apple ID? Yours? Your friends? Your dogs... ? I think we are going to need more information. You're probably best setting up the phone as a new phone and restoring from iCloud later on.

  • How to select the printer and select the ICC profile for printing with VBScript?

    I try to automate my printing procedure in photoshop. The problem is that I don't know how to select the printer and select the icc profile for printing with vbscript like I manually do in the print-menu in photoshop?
    Anyone has done this before?
    Thanx!
    jus

    Client/Server version:
    - D2KWUTIL.PLL library provides a 'Select Printer' dialog box to be used in Forms: WIN_API_DIALOG.SELECT_PRINTER
    http://guenter-huerkamp.dyndns.org/oracle-doc/docs/html/d2kwutil.html
    I suggest you to create a form to invoke the report, allowing user to select the printer and then pass it as parameter DESNAME

  • I want to get rid of a book in the iBooks "Purchased" collection, but when I touch the Edit button and select the book and then touch the Delete button, then the "Delete this copy" seletion, nothing happens.  How do I delete the book from the collection?

    I want to get rid of a book in the iBooks "Purchased" collection, but when I touch the Edit button and select the book and then touch the Delete button, then the "Delete this copy" seletion, nothing happens.  How do I delete the book from the collection?

    The Cloud by the song indicates that is is an iTunes purchase but it is not downloaded on the iPod. If you only want download iTunes purchases to show in the Music app go to Settings>itunes and pp Store and turn off Show aLL.

  • Error message too long to view the options buttons and select the right one!

    I am trying to send a group email change of address notice to a large number of recipients. It took me ages to edit all the addresses so I am keen not to have to start again. The email is not sending. This often happens and usually a warning message comes up telling me that it is because the server is the wrong one, and I just click edit message and select the correct server. The problem is that this time an error message is coming up with a huge list of emails that ends off the page. I can't read the end of the message or select the correct option. I have tried using tab to change options but that is not working either. I'm on a 27 inch screen so it shouldn't be a problem but I just cannot work out a way to read the end of the message. Nor can I delete the message. What can I do??

    Hi,
    You can use oracle's Substr Function with the odiRef.getPrevStepLog .
    Example
    insert into my_table.my_column values SUBSTR('<%=odiRef.getPrevStepLog("MESSAGE")%>',1,4000) ;
    This should give you the message staring from 1st position till 4000th position.
    Modify the query according to your need.
    Thanks,
    Sutirtha

  • Key pressed in Jlist and selecting the item of key list accordingly

    Hi,
    I have a JList with the items in sorted order.Now I want that if a person presses any key (say K) then the first item starting with K should be selected.Hmmm I can do it by addding a key listener to the list and cheking all the items in the list ,by traversing through the whole lenght of JList and selecting the item if it starts with the character of the key pressed.
    But i was thinking if there is any better way to do that?
    Regards Amin

    see bugid: 4654916 - it does say that the the
    scrolling for the JList should now work with keyboard
    selection.I have the same problem. Thanx for the hint with the bugid. Saw a good workaround there with a simple subclass of JList. Works for me although it is annoying to subclass JList all the time. The bug seems not to be fixed in the 1.4.1 JDK.
    Andreas

  • When I open the vi, Labview asks to find and select the same vi.

    This one is a little strange......
    As I was attempting to edit the block diagram of my program, that had just completed running with no errors, Labview (and Windows) locked up and I had to do a hard reset of the computer.  After rebooting and doubleclicking the main vi icon, Labview did the usual loading of all the dll's and other vi's and then it asked me to find and select the main program vi.  When I select it, it asks again and again.  If I ignore it Labview goes back to it's splash screen.  The program doesn't load at all.
    I'm sure having to reset the computer without shutting it down did this, but is there no way to open the file now at all?  I have a feeling that I'm going to be stuck having to reprogram everything again.
    Thanks,
    Tony

    First rule: always backup!
    Now, try some other things, instead of double clicking.
    For example, try placing your main VI as a subVI inside an empty VI or try calling it dynamically or opening all of its subVIs before opening it (although from your description I don't see why these should work). The other option is contacting NI and see if they can salvage your VI.
    Try to take over the world!

  • TS1398 My iphone5 ios6 goes on 3g although there is a wifi network available! When i go into settings, and select the network, it connects again! Is it software? Or hardware?

    My iphone5 ios6 goes on 3g although there is a wifi network available! When i go into settings, and select the network, it connects again! Is it software? Or hardware?

    this was happening with my phone the other night. i just went into the phone to settings > general > reset > reset all settings
    You can also try rebooting the router

  • I can access a website and select the 'print' option but the print misses out

    I can access a website and select the 'print' option but the print misses out photos that should be included in the print. It happens on more than one website. If I use Explorer it doesn't happen. I guess there must be a setting or something that I have not found? Any help very gratefully received. Than you.

    I don't know if this will help, but I found it by accident. When I send Word projects to recipients, it doesn't always read properly depending on their format. If they have a PC It distortes my  program, or they may have newer versions of Word. If you have your document showing select 'print' and on my print menu at the bottom left corner it has a button that says 'PDF'. Click on that and it gives you several options for a PDF. What I do if I'm emailing to someone is select the email option then you can always print from the email. Hope that helps.
    jr

Maybe you are looking for

  • "Exception Processing Message" error when clicking the Accessing Server Data link on the start page

    When I first started the application, I click the Accessing Server Data link on the start page.  I immediately got the error "Exception Processing Message c0000013 Parameters 75b6bf7c 4 75b6bf7c 75b6bf7c in a dialog box titled "Windows - No Disk".  I

  • Black screen between every clip that does not appear on timeline, only on MOV file

    Hello I originially had this issue  https://discussions.apple.com/message/17086997#17086997 I have now fixed the letterboxing issue but now have this problem (I did not have this issue before) where I get a very short black screen between each clip I

  • Loading .dlls in a java class

    when we load a .dll in a .java file by the command load library, i.e. somethg. like : System.loadLibrary("example"); where example is a .dll file, (example.dll) stored in hard disk, is it using JNI? How do we know whether its using JNI or not? is the

  • Where are Mail folders in [User]/Library?

    I get (but hate) Apple's striving for minimalism, but am I correct that it's now impossible to access Mail folders in the  [User]/Library? There must be a solution.

  • Interested in your opinion about PPBM7

    Bill and I are working on a new site and a new test. It looks like it will not take much longer and is nearly ready for CS6. We have invested lots of time in designing the new website and adding functionality and there is still as long way to go, but