Search This Blog

Friday, May 7, 2010

get past 6 month numbers from a calendar table in TeraData.

SELECT
year_of_calendar,
month_of_year
FROM
sys_calendar.calendar
WHERE
calendar_date<=current_date AND EXTRACT(month FROM calendar_date)<> EXTRACT(MONTH FROM current_date) AND
--because you want last 6 months and not current month
calendar_date>current_date-INTERVAL '6' MONTH
GROUP BY 1,2

ORDER BY 1 DESC, 2 DESC;



Results set  look like this:

Yr Mo
2010 03
2010 02
2010 01
2009 12
2009 11
2009 10

6 comments:

  1. Thanks for Information Teradata Online Training is one of the most emerging technologies in market. As more and more organization are moving their data warehouse in Teradata database, so the demand of Teradata Professionals are high. We at TeradataTech started giving online training sessions for all folks who are interested in learning this technology. People who are interested in learning the basics and advance features of Teradata Development can benefit from this training.

    ReplyDelete
  2. Teradata is a popular Relational Database Management System (RDBMS) suitable for large data warehousing applications. This is great post by admin on Teradata. Also learn Teradata from the best Teradata Online Training in your locality at CatchExperts.com

    ReplyDelete
  3. Thanks for the scenario well explained, for more tutorials and online training on Teradata visit TekSlate.

    ReplyDelete