Sql 以日期为导向参与蜂巢制作问题
我需要根据以下条件连接两个表。 我的桌子A看起来像Sql 以日期为导向参与蜂巢制作问题,sql,hadoop,hive,apache-spark-sql,Sql,Hadoop,Hive,Apache Spark Sql,我需要根据以下条件连接两个表。 我的桌子A看起来像 id,date 12,20190114 13,20190118 14,20190123 表B看起来像 id,date 13,20190108 12,20190108 13,20190101 13,20190115 14,20190129 14,20190122 当我应用连接条件时,我需要考虑下面的< /P> 1. id should be same for both tables 2.
id,date
12,20190114
13,20190118
14,20190123
表B看起来像
id,date
13,20190108
12,20190108
13,20190101
13,20190115
14,20190129
14,20190122
当我应用连接条件时,我需要考虑下面的< /P>
1. id should be same for both tables
2. date from table A should join with the date previous to the table B
dates(table B dates are weekly basis... I need to find the current week).
也就是说,表B中的日期是每周的日期。例如,对于id=13,表A的日期为20190118,表B中的相应日期为20180115,即表A所属的当前周
加入后我的成绩应该是怎么样的
id,a.date,b.date
13,20190118,2018015
12,20190114,20190108
14,20190123,20190122
有人能告诉我如何在蜂箱中实现这一点吗
select a.id, a.date, max(b.date)
from a join
b
on a.id = b.id and b.date <= a.date
group by a.id, a.date;
选择a.id、a.date、max(b.date)
从一个连接
B
在a.id=b.id和b.date上“在a.id=b.id和b.date@BigD上……代码按照您的问题指定的方式运行。问题是它是否在配置单元中运行。