简体   繁体   English

在postgres中生成星期间隔的日期

[英]generate date of week interval in postgres

I want a series in PostgreSQL which gives the date of every week interval before that date 我想要一个PostgreSQL中的系列,它给出该日期之前每个星期间隔的日期

Examples 例子

 1) Date Selected is 05/31/2013 So the series must be : 05/31/2013 05/24/2013 05/17/2013 05/03/2013 04/26/2013 2) Date Selected is 05/20/2013 So the series must be : 05/20/2013 05/13/2013 05/06/2013 04/29/2013 04/22/2013 

What I have done: 我做了什么:

SELECT * 
FROM generate_series('2013-05-03 00:00'::timestamp,'2013-05-31 12:00', '1 weeks')
  • It gives an increasing series from 2013-05-03. 从2013-05-03开始,它提供了越来越多的系列。
  • I want a decreasing series from 2013-05-31 我想从2013-05-31开始减少系列

Is it what you're after? 这是你要的吗?

SELECT *
  FROM generate_series('2013-05-31 12:00'::timestamp,
                       '2013-05-03', '-1 weeks');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM