0 问题描述
社交软件上如何判断自己关注的博主是否也关注了自己呢?现在有一张表为fans(粉丝表),表中有两个字段from_user,to_user,如果两者一致代表from_user关注了to_user。
1 数据准备
create table if not exists table15
(
from_user string comment '关注用户',
to_user string comment '被关注用户',
`timestamp` string comment '关注时间'
)
comment '关注表';
INSERT overwrite table fans
VALUES ("A","B","2022-11-28 12:12:12"),
("A","C","2022-11-28 12:12:13"),
("A","D","2022-11-28 12:12:14"),
("B","A","2022-11-28 12:12:15"),
("B","E","2022-11-28 12:12:16"),
("C","A","2022-11-28 12:12:17");
2 数据分析
思路一:如果是互相关注,很容易想到表自关联,具体sql如下:
--方法1
select
tmp1.from_user,
tmp1.to_user,
if(tmp2.from_user is not null,


1008

被折叠的 条评论
为什么被折叠?



