Q
Problem solve Get help with specific problems with your technologies, process and projects.

Finding and adding one to the max_date

I need the logic to find the max date and add one day to max_date. It would be great if you help me to find the...

logic in SQL.

Hopefully, a simple example can help you. Let's assume I have a table (MY_TAB) with two columns, ITEM_NAME and ITEM_DATE. I can find the maximum ITEM_DATE in the table by issuing the following query:

SELECT MAX(item_date) FROM my_tab;
How do I find the max ITEM_DATE for each ITEM_NAME?
SELECT item_name,MAX(item_date) FROM my_tab GROUP BY
item_name;
ITEM_DATE is a DATE datatype. The MAX function still returns a DATE datatype. To add one day to this date value, simply add '1' to it. For instance, to generate one day larger than the max date:
SELECT MAX(item_date)+1 FROM my_tab;
To find exactly one week after the max date:
SELECT MAX(item_date)+7 FROM my_tab;

For More Information


This was last published in November 2002

Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close