我非常确定以下查询在 Presto 上对我有用:
select segment, sum(count)
from modeling_trends
where segment='2557172' and date = '2016-06-23' and count_time between '2016-06-23 14:00:00.000' and '2016-06-23 14:59:59.000';
group by 1;
现在,当我运行它时(在 EMR 上的 Presto 0.147 上),我收到尝试将 varchar 分配给日期/时间戳的错误。
我可以使用以下方法使其工作:
select segment, sum(count)
from modeling_trends
where segment='2557172' and date = cast('2016-06-23' as date) and count_time between cast('2016-06-23 14:00:00.000' as TIMESTAMP) and cast('2016-06-23 14:59:59.000' as TIMESTAMP)
group by segment;
但感觉很脏...
有一个更好的方法吗?
与其他一些数据库不同,Trino 不会自动在 varchar 和其他类型之间进行转换,即使对于常量也是如此。强制转换有效,但更简单的方法是使用类型构造函数:
WHERE segment = '2557172'
AND date = date '2016-06-23'
AND count_time BETWEEN timestamp '2016-06-23 14:00:00.000' AND timestamp '2016-06-23 14:59:59.000'
您可以在此处查看各种类型的示例:https://trino.io/docs/current/language/types.html https://trino.io/docs/current/language/types.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)