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)

 

 

posted @ 2018-07-27 10:16  Fithon  阅读(1081)  评论(0编辑  收藏  举报