如何查询前一周的范围(即14天前到7天前)

时间:2016-11-09 19:51:27

标签: postgresql

我有以下查询,但我想在此之前的一周内提取这些数据。有没有办法在不引用今天或集合datestamp的情况下设置点到点之间的范围?

SELECT
  Count(orders.id) AS order_count
FROM
  orders
WHERE
  orders.requested_delivery_date between CURRENT_DATE - INTERVAL '7 days' and now()

1 个答案:

答案 0 :(得分:0)

select count(orders.id) as order_count
from orders
where
    date_trunc('week', requested_delivery_date) =
    date_trunc('week', current_date - interval '7 days')