更改 PostgreSQL 中计算的数据类型
我从一个日期中提取年份,然后从另一年中减去它,但由于某种原因,我不断得到一个浮点数。我该如何解决这个问题?非常感谢
SELECT 2022-(EXTRACT(YEAR FROM CAST(birthdate AS DATE)))AS age
FROM animals
I am extracting the year from a date and subtracting it from another year but for some reason I keep getting a float as a result. How can I fix this? Thanks a bunch
SELECT 2022-(EXTRACT(YEAR FROM CAST(birthdate AS DATE)))AS age
FROM animals
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
EXTRACT
函数返回类型为双精度
,如果您想获取整数值,可以尝试在使用<后将类型转换为INT
代码>提取。Because
EXTRACT
function return type wasdouble precision
, if you want to get value of integer you can try to convert the type toINT
after usingEXTRACT
.