我想从当前日期获得最近6个月的记录? [英] I want to get last 6 months records from the current date?
本文介绍了我想从当前日期获得最近6个月的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的情况下,
我希望在节点中使用squelize查询从当前日期获取最近6个月的记录,并希望按每月的记录数进行分组。
请帮帮我
我尝试过:
我希望在节点中使用squelize查询从当前日期获取最近6个月的记录,并希望按每月的记录数进行分组。
In my case,
I want to get last 6 months records from the current date using squelize query in the node and want to group by number of records of each month.
please help me
What I have tried:
I want to get last 6 months records from the current date using squelize query in the node and want to group by number of records of each month.
推荐答案
首先,你必须找出比现在大6个月的日期,为此,在PostgreSQL中使用INTERVAL,如下所示:
First, you have to find out the date that is six month older than now, to achieve this, use INTERVAL in PostgreSQL like this:
CURRENT_DATE - INTERVAL '6 months'
现在,您可以检索所有记录超过这个六个月大的日期。 ie
Now, you can retrieve all records that is older than this six-month-old date. i.e.
SELECT * from tablename where datefield > CURRENT_DATE - INTERVAL '6 months'
您应该熟悉 PostgreSQL:文档:8.2:日期/时间函数和操作符 [ ^ ]
这篇关于我想从当前日期获得最近6个月的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文