sqlalchemy presto 时间比较

大数据统计时,需要计算开仓订单减掉经纪商时间差,等于n 小时 或 星期几的订单。

presto sql语句如下:

select sum(profit) from t_table where open_time > ‘1970-01-01 00:00:00.0‘ 
and open_time < ‘2018-06-02 00:24:18.0‘ and hour(date_parse(open_time,‘%Y-%m-%d %H:%i:%S.%f‘))  - 6 = 21;


 

select sum(profit) from t_table where open_time > ‘1970-01-01 00:00:00.0‘ 
and open_time < ‘2018-06-02 00:24:18.0‘ and dow(date_parse(open_time,‘%Y-%m-%d %H:%i:%S.%f‘))  - 6 = 2;

 

sqlalchemy filter条件写法:

filter(extract(‘hour‘, cast(t_table.open_time,TIMESTAMP)) - 6 == 21)

--week

filter(extract(‘dow‘, cast(cast(t_table.open_time, TIMESTAMP) - text("interval ‘6‘ hour"),TIMESTAMP))  == 2)

 

and  [?nd; (?)n; ?nd]  详细X
基本翻译
conj. 和,与;就;而且;但是;然后
n. (And)人名;(土、瑞典)安德
网络释义
and: 和
and how: 的确
Yuan and: 元和

文章来自:https://www.cnblogs.com/fithon/p/9375991.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3