我有两张这样的桌子。 它们代表两个用户之间的关注者/关注者的互动。
users
---------------------------------------
id | username | <br>
1 | bobby | <br>
2 | jessica | <br>
3 | jonny | <br>
4 | mike | <br>
follows
----------------------------------------
id | userid_1 | userid_2 | <br>
1 | 1 | 2 | <br>
2 | 3 | 4 | <br>
3 | 4 | 1 | <br>
例如,将我的用户ID设置为1,我想要一个返回类似
的查询-----------------------------------------
username | userid_1 | userid_2 |<br>
jessica | 1 | 2 |<br>
mike | 4 | 1 |<br>
有任何帮助来解决这个问题吗? :)
答案 0 :(得分:1)
这比它最初看起来要复杂一点,因为你想要其他用户的名字:
select u.username, f.*
from follows f join
users u
on (u.id = f.userid_1 and f.userid_2 = 1) or
(u.id = f.userid_2 and f.userid_1 = 1)
where 1 in (f.userid_1, f.userid_2);
实际上,不需要where
子句(它由on
涵盖)。我认为它澄清了过滤。
答案 1 :(得分:0)
您可以在 generator 表中添加以下内容:
>>> c = [0.50, 0.52, 0.54, 0.56, 0.58, 0.60]
>>> a = np.array(c)
>>> a[(0.5 < a) & (a < 0.6)]
array([0.52, 0.54, 0.56, 0.58])
答案 2 :(得分:0)
Select username, userid_1, userid_2
from users, follows
where users.id = follows.id