Hive sql查询不返回任何结果+ Sparklyr中的等效项

问题描述 投票:1回答:1

数据看起来像:

ARTICLE_ID, ORDER_ID, ARTICLE_TIME
2567, 1112, 2019-01-16 20:40:00.0
2670, 1117, 2019-01-16 21:40:00.0
2569, 1112, 2019-01-16 20:45:00.0

假设我们有很多订单,每个订单包含几篇文章。每篇文章都在特定时间购买article_time,

我的问题是,从购买特定article_id开始,使所有具有article_time在-/ + 300s之间的商品成为第一个大于或等于给定值的商品。

假设我们正在寻找的值为66.5。

1-我们必须使第一个值(article_id)大于66.5(此处为67)2-我们采用发现值(67)t的时间戳,并对其进行过滤,以便在此时间戳之内-/ + 300s内购买所有商品t

这是我尝试的查询,但未返回任何内容。

SELECT order_id, article_time as `time`, article_id as `article`
FROM  
   db.orders `a`
JOIN 
   (select order_id as `idd`, min(article_id)  as `minn` FROM db.orders   
   WHERE article_id>=66.5   
   AND category=1  
   GROUP BY order_id) `b`  
ON (order_id=idd AND a.article_time between b.minn-300 AND  b.minn+300)

我也尝试使用sparklyr创建它,但我不知道如何在dyplr中进行类似的连接:

orders<- orders_tbl%>%
group_by(orders$order_id)%>%
arrange(orders$time)%>%
filter(...)

dplyr hiveql sparklyr
1个回答
0
投票

我们可以直接过滤而不是执行联接。

Hive查询-

select order_id, article_id,article_time from db.orders
where article_time >= (from_unixtime(unix_timestamp(select article_time from db.orders where article_id = 66.5)-300)) 
and article_time < (from_unixtime(unix_timestamp(select article_time from db.orders where article_id = 66.5)+300));
© www.soinside.com 2019 - 2024. All rights reserved.