【发布时间】:2019-04-01 19:30:04
【问题描述】:
我有下表
ABC Date
200 2019-02-22
-200 2019-02-23
1200 2019-02-24
-500 2019-02-25
'
'
'
'
-889 2015-01-11
我需要从 ABC 获取每个月最后一周的每一天的值
select ABC
from table 1
where date between '2019-03-26' and '2019-03-30'
这是 2019 年 3 月的月份。我如何创建一个循环,以便在 3 年内每个月的最后一周的每一天都显示值
【问题讨论】:
-
你如何定义一个月的上周?整周,部分周?您一周的开始日期是星期天还是星期一?
-
上周22-29,开始日是星期一.....所以基本上我会检查每个月22-29日的值。输出看起来像这样.. ABC 200 日期:2019-03-22,ABC 100 日期:2019-03-22.........ABC 200 日期:2018-02-22
-
每月 22-29 日的值 =
where extract(day from mydate) between 22 and 29 -
怎么才能拿到这3年?...
-
and mydate between add_months(current_date,-3*12) and current_date,也许trunc(add_months(current_date,-3*12), 'mon')包括完整的第 1 个月。