如何从 Athena 的 DOB 中找到年龄?
how to find Age from DOB in Athena?
这是我从 DOB 列中找出年龄的查询:
date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age
我收到以下错误:
SYNTAX_ERROR: line 4:47: '-' cannot be applied to varchar, varchar
感谢您的帮助!
你应该可以使用 function DATE_DIFF()
来解决这个问题。来自文档:
date_diff(unit, timestamp1, timestamp2)
→ bigint
Returns timestamp2 - timestamp1
expressed in terms of unit.
尝试:
DATE_DIFF('year', c.memberdob, current_timestamp) as age
这是我从 DOB 列中找出年龄的查询:
date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age
我收到以下错误:
SYNTAX_ERROR: line 4:47: '-' cannot be applied to varchar, varchar
感谢您的帮助!
你应该可以使用 function DATE_DIFF()
来解决这个问题。来自文档:
date_diff(unit, timestamp1, timestamp2)
→bigint
Returns
timestamp2 - timestamp1
expressed in terms of unit.
尝试:
DATE_DIFF('year', c.memberdob, current_timestamp) as age