雅典娜大于日期列中的条件 [英] Athena greater than condition in date column

查看:109
本文介绍了雅典娜大于日期列中的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Athena 上运行以下查询.

I have the following query that I am trying to run on Athena.

SELECT observation_date, COUNT(*) AS count
FROM db.table_name
WHERE observation_date > '2017-12-31'
GROUP BY observation_date

但是它产生了这个错误:

However it is producing this error:

SYNTAX_ERROR: line 3:24: '>' cannot be applied to date, varchar(10)

这对我来说似乎很奇怪.我的查询中是否存在错误,或者 Athena 是否无法处理日期列上的大于运算符?

This seems odd to me. Is there an error in my query or is Athena not able to handle greater than operators on date columns?

谢谢!

推荐答案

在进行此比较之前,您需要使用强制转换来正确设置日期格式.请尝试以下操作:

You need to use a cast to format the date correctly before making this comparison. Try the following:

SELECT observation_date, COUNT(*) AS count
FROM db.table_name
WHERE observation_date > CAST('2017-12-31' AS DATE)
GROUP BY observation_date

在 Fiddler 中查看:SQL Fiddle

Check it out in Fiddler: SQL Fidle

2019 年 7 月 17 日更新

为了反映评论

SELECT observation_date, COUNT(*) AS count
FROM db.table_name
WHERE observation_date > DATE('2017-12-31')
GROUP BY observation_date

这篇关于雅典娜大于日期列中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆