如何在雅典娜找到DOB的年龄?

问题描述 投票:1回答:1

这是我从DOB列中查找年龄的查询:

date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age

我收到以下错误:

SYNTAX_ERROR:第4:47行:' - '不能应用于varchar,varchar

感谢您的帮助!

sql amazon-athena presto
1个回答
2
投票

你应该能够使用function DATE_DIFF()来解决这个问题。从文档:

date_diff(unit, timestamp1, timestamp2) bigint

返回以单位表示的timestamp2 - timestamp1

尝试:

DATE_DIFF('year', c.memberdob, current_timestamp) as age
© www.soinside.com 2019 - 2024. All rights reserved.