DB2 SQL last (month, quarter, year) last month, last quarter, last year (commonly used in statistics)

Source: Internet
Author: User

DB2 SQL last period (month, quarter, year) last month end of month, last quarter end, last year (often used in statistics) SELECTcurrent timestamp-day (current date) days, -- last month end of month, can know the New Year/* to_date ('1970-02-23 ', 'yyyy-mm-dd')-day (current date) days, -- last month, can know the New year www.2cto.com */case when TO_CHAR ('2017-06-22 ', 'q') = '1' THEN to_char (year ('2017-12-01')-1) | '-12' when TO_CHAR ('2017-06-22', 'q') = '2' THEN to_char (year ('2017-06-22 ')) | '-3' when TO_CHAR ('2017-01-01', 'q') = '3' THEN to_char (year ('2017-12-01 ')) | '-6' when TO_CHAR ('2017-01-01', 'q') = '4' THEN to_char (year ('2017-12-01 ')) | '-9' end as tt, -- the previous quarter month can know the current date of the New Year-(month (current date)-1) month-day (current date) day -- from sysibm at the end of last year. sysdummy1;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.