两张表,一张user表,一张relation表
# 建立user表
create table user(
name varchar(30) not null
)
# 建立relation表
create table relation(
uid int not null,
rid int not null
)
# 1.查询用户a关注的人
select name from user where id in (select rid from relation where uid = a)
# 2.查询关注用户a的人
select name from user where id in (select uid from relation where rid = a)
# 3.查询和a相互关注的人
select name from user where id in (select uid from relation where rid = a and uid in (select rid from relation where uid = a))