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...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
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.