MySQL SELECT 查询:将 28 天添加到财务季度的最后日期
MySQL SELECT Query: Add 28 days to the last date of a financial quarter
我想在一个季度的最后一天加上 28 天。
我目前有以下方法来确定季度期间,然后如何将 28 天添加到该季度最后一个月的最后一天。
CASE -- Results: 2011-Q4 (Financial Year-Qtr)
WHEN MONTH(T5.date_purchased) BETWEEN 1 AND 3 THEN concat((YEAR(T5.date_purchased) - 1), '-', 'Q3')
WHEN MONTH(T5.date_purchased) BETWEEN 4 AND 6 THEN concat((YEAR(T5.date_purchased) - 1), '-', 'Q4')
WHEN MONTH(T5.date_purchased) BETWEEN 7 AND 9 THEN concat((YEAR(T5.date_purchased) - 0), '-', 'Q1')
WHEN MONTH(T5.date_purchased) BETWEEN 10 AND 12 THEN concat((YEAR(T5.date_purchased) - 0), '-', 'Q2')
END AS FYrQtr,
我不需要考虑任何异常情况,只需在下个季度的下个月 28 号。
我尝试了以下方法,但当然会在订单日期而不是财务季度后增加 28 天。 (我不需要时间)
CASE -- Results: 2012-06-20 07:20:07 not 2012-07-28
WHEN MONTH(T5.date_purchased) BETWEEN 1 AND 3 THEN date_add(T5.date_purchased, Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 4 AND 6 THEN date_add(T5.date_purchased, Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 7 AND 9 THEN date_add(T5.date_purchased, Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 10 AND 12 THEN date_add(T5.date_purchased, Interval 28 day)
END AS FRangeQtrBAS,
非常感谢。
从 purchasedate 中获取年份并将其与已知的季度月末日相连接:
CASE
WHEN MONTH(T5.date_purchased) BETWEEN 1 AND 3 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-03-31'), Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 4 AND 6 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-06-30'), Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 7 AND 9 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-09-30'), Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 10 AND 12 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-12-31'), Interval 28 day)
END AS FRangeQtrBAS
我想在一个季度的最后一天加上 28 天。
我目前有以下方法来确定季度期间,然后如何将 28 天添加到该季度最后一个月的最后一天。
CASE -- Results: 2011-Q4 (Financial Year-Qtr)
WHEN MONTH(T5.date_purchased) BETWEEN 1 AND 3 THEN concat((YEAR(T5.date_purchased) - 1), '-', 'Q3')
WHEN MONTH(T5.date_purchased) BETWEEN 4 AND 6 THEN concat((YEAR(T5.date_purchased) - 1), '-', 'Q4')
WHEN MONTH(T5.date_purchased) BETWEEN 7 AND 9 THEN concat((YEAR(T5.date_purchased) - 0), '-', 'Q1')
WHEN MONTH(T5.date_purchased) BETWEEN 10 AND 12 THEN concat((YEAR(T5.date_purchased) - 0), '-', 'Q2')
END AS FYrQtr,
我不需要考虑任何异常情况,只需在下个季度的下个月 28 号。
我尝试了以下方法,但当然会在订单日期而不是财务季度后增加 28 天。 (我不需要时间)
CASE -- Results: 2012-06-20 07:20:07 not 2012-07-28
WHEN MONTH(T5.date_purchased) BETWEEN 1 AND 3 THEN date_add(T5.date_purchased, Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 4 AND 6 THEN date_add(T5.date_purchased, Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 7 AND 9 THEN date_add(T5.date_purchased, Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 10 AND 12 THEN date_add(T5.date_purchased, Interval 28 day)
END AS FRangeQtrBAS,
非常感谢。
从 purchasedate 中获取年份并将其与已知的季度月末日相连接:
CASE
WHEN MONTH(T5.date_purchased) BETWEEN 1 AND 3 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-03-31'), Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 4 AND 6 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-06-30'), Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 7 AND 9 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-09-30'), Interval 28 day)
WHEN MONTH(T5.date_purchased) BETWEEN 10 AND 12 THEN date_add(CONCAT(YEAR(T5.date_purchased), '-12-31'), Interval 28 day)
END AS FRangeQtrBAS