select user_id, prod_and_ts.product_id as product_id, prod_and_ts.timestamps as
timestamps from testingtable2 LATERAL VIEW explode(purchased_item) exploded_table
as prod_and_ts;
通过使用上述查询,我得到以下输出。
USER_ID | PRODUCT_ID | TIMESTAMPS
------------+------------------+-------------
1015826235 220003038067 1004841621
1015826235 300003861266 1005268799
1015826235 140002997245 1061569397
1015826235 *200002448035* 1005542471
如果您比较上面的output from the query with the below Table2 data
,那么product_id
中的与下面数据中最后一行中的last line of above output
不匹配。ITEM_ID
Table2
BUYER_ID | ITEM_ID | CREATED_TIME
-------------+-------------------+------------------------
1015826235 220003038067 2001-11-03 19:40:21
1015826235 300003861266 2001-11-08 18:19:59
1015826235 140002997245 2003-08-22 09:23:17
1015826235 *210002448035* 2001-11-11 22:21:11
所以我的问题是
查找所有PRODUCT_ID(ITEM_ID)
与特定 BUYER_ID 或 USER_ID 对应的数据TIMESTAMPS(CREATED_TIME)
不匹配的和。Table2
所以我需要为上面的例子显示这样的结果 -
BUYER_ID | ITEM_ID | CREATED_TIME | USER_ID | PRODUCT_ID | TIMESTAMPS
-----------+-------------------+-------------------------+---------------+------------------+------------------
1015826235 *210002448035* 2001-11-11 22:21:11 1015826235 *200002448035* 1005542471
我需要加入我用 table2 编写的上述查询以获得上述结果。所以我需要在 JOINING 过程中使用我上面的查询。这让我很困惑。任何建议将不胜感激。
更新:-
我编写了以下查询,但不知何故我无法实现我想要实现的输出。谁能帮我这个?
SELECT table2.buyer_id, table2.item_id, table2.created_time from
(select user_id, prod_and_ts.product_id as product_id, prod_and_ts.timestamps as
timestamps from testingtable2 LATERAL VIEW explode(purchased_item) exploded_table
as prod_and_ts) prod_and_ts JOIN table2 where
prod_and_ts.user_id = table2.buyer_id
and (product_id <> table2.item_id or
timestamps <> UNIX_TIMESTAMP(table2.created_time));