标签:sku info user1 用户 Hive 收藏 101 id 刷题
需求描述
现需要请向所有用户推荐其朋友收藏但是用户自己未收藏的商品,请从好友关系表(friendship_info)和收藏表(favor_info)中查询出应向哪位用户推荐哪些商品。
期望结果如下:
user_id
(用户id)
|
sku_id
(应向该用户推荐的商品id)
|
101
|
2
|
101
|
4
|
101
|
7
|
101
|
9
|
101
|
8
|
101
|
11
|
101
|
1
|
需要用到的表:
好友关系表:friendship_info
user1_id(用户1 id)
|
user2_id(用户2 id)
|
101
|
1010
|
101
|
108
|
101
|
106
|
收藏表:favor_info
user_id(用户id)
|
sku_id(商品id)
|
create_date(收藏日期)
|
101
|
3
|
2021-09-23
|
101
|
12
|
2021-09-23
|
101
|
6
|
2021-09-25
|
参考SQL
select t.user1_id user_id, t.sku_id
from (select user1_id, sku_id
from friendship_info f
join favor_info f1 on f.user2_id = f1.user_id
group by user1_id, sku_id) t
left join
(select user1_id, sku_id
from friendship_info f
join favor_info f1 on f.user1_id = f1.user_id
group by user1_id, sku_id) t1
on t.user1_id = t1.user1_id and t.sku_id = t1.sku_id
where t1.user1_id is null
and t1.sku_id is null
order by 1;
标签:sku,
info,
user1,
用户,
Hive,
收藏,
101,
id,
刷题
From: https://www.cnblogs.com/wdh01/p/17041036.html