我希望获得用户朋友的列表,但是性别明智,在1个电话中。喜欢与用户或性别相同的朋友性别相同的朋友。目前,我必须拨2个电话。首先,获取用户的性别,然后获取第二个这样的列表
SELECT uid, name
FROM user
WHERE uid IN (
SELECT uid2
FROM friend
WHERE uid1 =me()
)
AND sex='< gender >'
答案 0 :(得分:1)
为了获得与您的性别相同的朋友:
获得性别:
select sex from user where uid = me()
结交所有朋友:
select uid, sex from user where uid in (select uid1 from friend where uid2 = me())
两者的结合:
select uid, sex from user where
uid in
(
select uid1 from friend where uid2 = me()
)
and
sex in
(
select sex from user where uid = me()
)
修改
对于异性
select uid, sex from user where
uid in
(
select uid1 from friend where uid2 = me()
)
and not(sex in
(
select sex from user where uid = me()
))
这会在一个查询中向您回复与您相同/异性的所有朋友。