-1

我想在 1 个电话中获取用户朋友的列表,但性别明智。喜欢与用户性别相同的朋友或异性朋友。目前,我必须为此打 2 个电话。首先,获取用户的性别,其次获取这样的列表

SELECT uid, name 
  FROM user 
 WHERE uid IN (
             SELECT uid2 
               FROM friend 
              WHERE uid1 =me()
              ) 
   AND sex='< gender >'
4

1 回答 1

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()
))

这将在一个查询中返回所有与您性别相同/异性的朋友。

于 2013-10-07T15:04:41.440 回答