postgresql是如何求年龄的_postgresql – 如何计算出生日期的下一个生日?

select birth_date,cast(birth_date + ((extract(year from age(birth_date)) + 1) * interval '1' year) as date) as next_birthday

from person

where name = 'Bob'

表达式(提取物(年龄(birth_date))1)*间隔“1”年计算(完整)年份下一个生日的年龄.将其添加到出生日期时,这将给下一个生日.

由于日期间隔返回时间戳(包括时间),因此需要使用强制转换才能获得真实的日期.

如果你删除where条件,你将获得所有“下一个”生日.

您还可以获取即将到来的生日列表,例如:接下来的30天使用这样的东西:

select next_birthday,next_birthday - current_date as days_until_next

from (

select birth_date,cast(birth_date + ((extract(year from age(birth_date)) + 1) * interval '1' year) as date) as next_birthday

from person

) as upcoming

where upcoming.next_birthday <= current_date + 30

order by next_birthday;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值