生成查询以连接不同的记录

eiee3dmh  于 2021-06-28  发布在  Hive
关注(0)|答案(2)|浏览(311)

sql/hive中的新手。。。

SELECT id,seed, day FROM  table_1 WHERE  day = to_date('2016-06-09') limit 5;
302766500   R388899 2016-06-09
692010468   R61140  2016-06-09
662084962   R165803 2016-06-09
1818260515  R411276 2016-06-09
646246322   R426737 2016-06-09

SELECT id, exp, day FROM table_2 WHERE day = to_date('2016-06-09')  limit 5;
OK
2595    e137_1  2016-06-09
2595    e137_2  2016-06-09
4372    e137_1  2016-06-09
7256    e137_1  2016-06-09
18674   e137_1  2016-06-09
Time taken: 1.475 seconds, Fetched: 5 row(s)

如表2所示。。侦听器id重复(2595)。。
所以,从表2中,我想找出两天范围内不同的id
然后在给定的日期范围内从表1中找到这些ID的种子。。

SELECT id, seed FROM table_1 WHERE day = to_date('some date')
JOIN (
SELECT DISTINCT id FROM table_2 WHERE day = to_date('some_date')
) l
ON l.id = id;

但我有个错误:

ParseException line 3:0 missing EOF at 'JOIN' near ')'
mwecs4sa

mwecs4sa1#

始终加入“发件人”部分:

SELECT id, seed FROM table_1 JOIN (
SELECT DISTINCT id FROM table_2 WHERE day = to_date('some_date')
) l
ON l.id = table_1.id
WHERE day = to_date('some date')
dvtswwa3

dvtswwa32#

似乎哪里的位置不对

SELECT table_1.id, table_1.seed FROM table_1 
JOIN (
SELECT DISTINCT id FROM table_2 WHERE day = to_date('some_date')
) l
ON l.id = table_1.id
WHERE table_1.day = to_date('some date')

;

相关问题