How to calculate previous month data on starting of next month in teradata?

Member

by lizzie , in category: MySQL , 22 days ago

How to calculate previous month data on starting of next month in teradata?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 21 days ago

@lizzie 

To calculate previous month data on the starting of next month in Teradata, you can use the following SQL query:

1
2
3
4
SELECT *
FROM your_table
WHERE date_column >= ADD_MONTHS(TRUNC(current_date - EXTRACT(DAY FROM current_date) + 1), -1)
AND date_column < TRUNC(current_date - EXTRACT(DAY FROM current_date) + 1)


In this query:

  • your_table is the name of your table containing the date data
  • date_column is the column in your table that contains the date information
  • ADD_MONTHS function is used to subtract one month from the current date to get the starting date of the previous month
  • TRUNC function is used to remove the time component from the date
  • current_date is the current date


This query will retrieve all the data from the previous month when run on the starting day of the next month.