postgressql中的dateadd

发布于 2025-01-29 21:28:34 字数 541 浏览 2 评论 0原文

我有这张学生桌子桌,想知道那些已经早点完成的桌子。

student-id, loan_amount, date_given, terms, last_paymnt
xxxx        xxxx         04/03/2010   36    08/09/2012
xxxx        xxxx         16/09/2011   45    13/12/2017

我的逻辑是抓取enter(当前整数) date_given作为几个月以cte中的预定日期,然后在该日期和giend-date之间获取另一个减法,以使结果在几个月,所以我可以老板和莱特斯。

我正在尝试以下操作,但没有成功:

select date_given + interval 'terms month'
from Student_loan

我将如何将整数添加到日期,并在我的桌子上有几个月甚至减去两个日期并返回一个月?

I have this student_loan table and would like to know those that have finished early.

student-id, loan_amount, date_given, terms, last_paymnt
xxxx        xxxx         04/03/2010   36    08/09/2012
xxxx        xxxx         16/09/2011   45    13/12/2017

My logic is to grab to add the terms (currently integer) to the
date_given as months to have a presumed finished date in a cte then grab another subtraction between that date and the given-date to have the result in months so I can the earlies and the lates.

I am trying the below but without success:

select date_given + interval 'terms month'
from Student_loan

How would I add that integer to the date and have a number of months or even subtract the two dates in my table and return a number of month?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡绿茶香 2025-02-05 21:28:34

您可以使用make_interval()

select date_given + make_interval(months => terms)
from student_loan

或将一个月间隔乘以列的值:

select date_given + terms * interval '1 month'
from student_loan

,甚至减去我的桌子中的两个日期并返回一个月?

只需减去它们,结果就是几天的数量,因为这两个列都是(或至少似乎是)date值:

select last_paymnt - date_given as num_days
from student_loan

You can use make_interval()

select date_given + make_interval(months => terms)
from student_loan

Alternatively multiply a one month interval with the value of the column:

select date_given + terms * interval '1 month'
from student_loan

or even subtract the two dates in my table and return a number of month?

Just subtract them, the result of that is the number of days as both columns are (or at least seem to be) date values:

select last_paymnt - date_given as num_days
from student_loan
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文