一年中每个季度的Oracle SQL第一和最后一天 [英] Oracle SQL first and last day of quarter of any year
本文介绍了一年中每个季度的Oracle SQL第一和最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以计算任何一年中三个季度的第一天和最后一天. 2012年,2013年或2014年
Is there any way i can calculate the first and last day of the three quarters in any year . 2012 , 2013 or 2014
SELECT ADD_MONTHS(TRUNC(SYSDATE, 'Q'), -3) AS First,
TRUNC(SYSDATE, 'Q') - 1 AS Last
FROM DUAL
计算本年度的第一季度.我想计算任何一年的第一季度吗?
calculates the first quarter of current year. i want to calculate the first quarter of any year ?
推荐答案
您可以执行以下操作:
with q(qtr) as(
select add_months(
DATE '2013-01-01'
, (level-1)*3
)
from dual
connect by level <= 4
)
select qtr as first_day
, last_day(add_months(qtr, 2)) as last_day
from q
结果:
FIRST_DAY LAST_DAY
----------- -----------
01.01.2013 31.03.2013
01.04.2013 30.06.2013
01.07.2013 30.09.2013
01.10.2013 31.12.2013
这篇关于一年中每个季度的Oracle SQL第一和最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文