HQL/SQL - Return 在日期字段中具有多个值中的任何一个值的记录

HQL/SQL - Return records that have any one of multiple values in a date field

我希望能够编写查询,其中只有记录 returned 具有由列表中的一个或多个日期组成的特定字段值。

例如(我认为这行得通,但行不通):

select * from someDatabase.someTable where dateField in ('2017-11-10','2017-11-14','2017-11-28');

所以我希望这只会 return 记录 dateField 包含 ('2017-11-10','2017-11-14','2017-11-28')

中的任何一个或所有日期

当我 运行 这样的查询时,我得到错误:

FAILED: SemanticException [Error 10014]: Line 1:105 Wrong arguments ''2017-11-20'': The arguments for IN should be the same type! Types are: {date IN (string, string)}

非常感谢任何帮助。谢谢。

能否请您使用以下方法检查 table 的结构:

describe extended someDatabase.someTable;

这看起来像是数据类型不匹配错误,因为您的 dateField 似乎是 Map 而不是 Date。

理想的日期比较如下(现在无法测试语法):

select * from someDatabase.someTable where dateField in ((from_unixtime(unix_timestamp('2017-11-10', 'YYYY-MM-dd'),'YYYY-MM-dd'),(from_unixtime(unix_timestamp('2017-11-14', 'YYYY-MM-dd'),'YYYY-MM-dd'),(from_unixtime(unix_timestamp('2017-11-28','YYYY-MM-dd'));

您需要使用 CAST 函数将 IN 中的参数转换为 date

CAST( expression AS type )

您的查询应该是这样的:

select * from someDatabase.someTable where dateField in (cast('2017-11-10' as date),cast('2017-11-14' as date),cast('2017-11-28' as date))