0

我在社交网站上工作,因为我有 3 个 SQL 表来搜索用户的建议。例如:用户必须在注册时选择一个类别。

用户表:

userID   | username   | categoryID  | createdOn 
101          abc           2           20-07-11

..... 同样地

类别表

  CategoryID   | CategoryName
       0              Health
       1              IT
       2              Construction

..... 同样地

另一个表是兴趣类别,用户必须选择最多 5 个兴趣,如下所示

兴趣类别

UserInterestID   |   UserID    | location  |    CategoryID    | CreatedBy
0                     101          India           1             101
1                     101          UK              3             101    
2                     101          CA              10            101
3                     101          RA              14            101
4                     510          LA              5             510

现在我想通过

  1. 来自兴趣类别的用户
  2. 我自己类别的用户

我们如何使用 SQL Server 2005 脚本根据上述条件获得所有建议用户?

4

1 回答 1

0

对于#1,请尝试:

select u.* from User u, InterestCategories i where u.UserID = i.UserID and i.CategoryID = %InterestCatagoryID%;

对于#2,请尝试:

select u.* from User u, InterestCategories i, User m where u.UserID = i.UserID and i.CategoryID = m.CatetoryID and m.UserID = %MyUserID%;
于 2011-07-19T10:15:33.683 回答