If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to use maximum of date function in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-06-11, 14:28
dinesh1985 dinesh1985 is offline
Registered User
 
Join Date: Sep 2010
Posts: 6
Question How to use maximum of date function in db2

Hello Folks,
I am having a below example
Code:
CAR_NAME   SERVICE_DATE
------------------------------------
ALTIMA        01/01/2007
ALTIMA        03/01/2007
ALTIMA        05/02/2008
FORD GT      01/01/2009
FORD GT      01/01/2010
FORD GT      01/06/2010
FORD GT      01/01/2011
In the above example, CARs and their servicing dates are stored in the table. Altima has done three services in which the latest service date is done on 05/02/2008 and FORD GT has done the latest service on 01/01/2011.

I need to write a db2 query to fetch the vehicles for which the latest service is done before Dec 2008. For the Above example, the expected result is ALTIMA.

I am trying something like this
Code:
SELECT DISTINCT CAR_NAME FROM CAR_SERVICE_TABLE WHERE MAX(SERVICE_DATE) < '12/31/2008' WITH UR
But this is not working.

I am getting the error as
SQL0120N invalid use of an aggregate function or OLAP function. SQLSTATE = 42903.

Please help me in writing the query
Reply With Quote
  #2 (permalink)  
Old 06-06-11, 14:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Reply With Quote
  #3 (permalink)  
Old 06-06-11, 14:45
dinesh1985 dinesh1985 is offline
Registered User
 
Join Date: Sep 2010
Posts: 6
Question description pls

Quote:
Originally Posted by n_i View Post
Hi NI,
Thanks for your reply. Can you please tell me where to look for in the given link.?
Reply With Quote
  #4 (permalink)  
Old 06-06-11, 22:08
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
GROUP BY and HAVING clauses.
Reply With Quote
Reply

Tags
db2 9.1, max(date), select max

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On