代码之家  ›  专栏  ›  技术社区  ›  Murli

如何从postgres中时间戳从上月某一天到本月某一天的表中获取记录?

  •  0
  • Murli  · 技术社区  · 8 年前

    我有一个客户访问表,我的要求是获得上个月从第3天到本月第2天的记录,其中包含标志“Y”。我怎样才能在博士后做到这一点。下面是我的桌子样本。感谢您的帮助。

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  1
  •   krithikaGopalakrishnan    8 年前

    使用 make_date()

    select * from customer_visit 
         where created_time > make_date(2018, date_part('month', now())::int - 1, 03)
         and created_time <= make_date(2018, date_part('month', now())::int, 02) 
         and flag = 'Y';
    

    您可以使用date\u part('year',timestamp)从当前日期中提取年份。