日期:2014-05-17 浏览次数:20504 次
---------------------------------
-- Author: HEROWANG(让你望见影子的墙)
-- Date : 2012-11-06 12:35:43
-- blog : blog.csdn.net/herowang
---------------------------------
IF OBJECT_ID('[tb]') IS NOT NULL
DROP TABLE [tb]
go
CREATE TABLE [tb] (事件ID INT,用户 VARCHAR(1))
INSERT INTO [tb]
SELECT 1,'A' UNION ALL
SELECT 1,'B' UNION ALL
SELECT 1,'C' UNION ALL
SELECT 1,'D' UNION ALL
SELECT 2,'B' UNION ALL
SELECT 2,'F'
select * from [tb]
IF OBJECT_ID('[tb2]') IS NOT NULL
DROP TABLE [tb2]
go
CREATE TABLE [tb2] (关注 VARCHAR(1),被关注 VARCHAR(1))
INSERT INTO [tb2]
SELECT 'A','B' UNION ALL
SELECT 'A','C' UNION ALL
SELECT 'A','F'
select s.事件id,s.用户 from tb join tb2 on tb.用户=tb2.关注
join tb s on tb2.被关注=s.用户
where s.事件id=1
1 B
1 C
select 被关注
from TB1 as a inner join TB2 as b on a.用户=b.关注
where 事件ID=1 and 关注='A'