두 주간에 주간 범위를 생성 할 수있는 솔루션을 찾고 있습니다. 여기서 요일 범위는 요일을 기준으로합니다.
예 :요일을 기준으로 두 날짜 사이의 주간 범위 생성
date1 = 2011-12-17 date2 = 2012-05-16
결과 : 나는 PostgreSQL을 내 SQL을 작성했습니다
week1 2011-12-17 to 2011-12-17 -- since it the first date false on a saturday
week2 2011-12-18 to 2011-12-24
...
last week 2012-05-13 to 2012-05-16
:
SELECT
time_series.cur
,case (6 - date_part('dow', cur)::int) = 0
when true then cur
else case time_series.cur + (6 - date_part('dow',cur)::int) < current_date
when true then time_series.cur + (6 - date_part('dow', cur)::int)
else current_date
end
end
as nxt
FROM
(select generate_series(current_date - 151
, current_date, '1 day')::date AS cur) time_series
where cur < current_date
and case (current_date - 151 != cur and cur != current_date)
when true then date_part('dow', cur)::int = 0
else true
end
이 할 수있는 청소기 방법이 있나요?
[이 최근 질문] (http://stackoverflow.com/q/10597101/939860)까지 후속 조치를 취하십시오. –