求互相关注的人数?
select count(1) from tst t1
inner join tst t2
on t1.uid = t2.uuid and t1.uuid = t2.uid;
求关注了4的总关注数?
select count(1) from tst t1
inner join (select uid from tst where uuid = '4') t2
on t1.uid = t2.uid;
-- ----------------------------
-- Table structure for `tst`-- ----------------------------
DROP TABLE IF EXISTS `tst`;
CREATE TABLE `tst` (
`uid` int(10) NOT NULL,
`uuid` int(10) NOT NULL,
`desc` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tst
-- ----------------------------
INSERT INTO `tst` VALUES ('1', '2', null);
INSERT INTO `tst` VALUES ('1', '3', null);
INSERT INTO `tst` VALUES ('1', '4', null);
INSERT INTO `tst` VALUES ('2', '5', null);
INSERT INTO `tst` VALUES ('2', '1', null);
INSERT INTO `tst` VALUES ('3', '4', null);
INSERT INTO `tst` VALUES ('3', '1', null);
INSERT INTO `tst` VALUES ('5', '4', null);
INSERT INTO `tst` VALUES ('5', '6', null);
INSERT INTO `tst` VALUES ('5', '1', null);
本文介绍如何使用SQL查询来统计社交网络中用户的关注关系,包括互相关注人数及特定用户被关注的总数。通过内连接操作实现精准匹配,适用于分析用户间的关系网络。
1191

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



