Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何从雅典娜的DOB找到年龄?_Sql_Datetime_Presto_Amazon Athena_Date Arithmetic - Fatal编程技术网

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

Sql 如何从雅典娜的DOB找到年龄?,sql,datetime,presto,amazon-athena,date-arithmetic,Sql,Datetime,Presto,Amazon Athena,Date Arithmetic,以下是我从DOB列中查找年龄的查询: date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age 我遇到以下错误: 语法错误:第4:47行:“-”不能应用于varchar,varchar 谢谢你的帮助 您应该能够使用以下方法解决此问题。从文件中: date_diff(单位,时间1,时间2)→ bigint 返回以单位表示的timestamp2-timestamp1 尝试:

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

date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age
我遇到以下错误:

语法错误:第4:47行:“-”不能应用于varchar,varchar


谢谢你的帮助

您应该能够使用以下方法解决此问题。从文件中:

date_diff(单位,时间1,时间2)
→ <代码>bigint

返回以单位表示的
timestamp2-timestamp1

尝试:


date\u格式
返回一个字符串,因此您尝试减去两个字符串。而是先减去日期,然后将结果转换为字符串。类似于:
date\u格式(当前\u时间戳-c.memberdob,“%Y\u%m\u%d”)
@pault my memberdob有一个时间戳
DATE_DIFF('year', c.memberdob, current_timestamp) as age