我已经写了一个查询,其中我正在检查用户是否将其隐私设置为每个人都将返回该结果,如果用户设置为网络,那么在我的情况下,当前用户5将检查用户是否必须是他的朋友或朋友朋友,如果它设置为朋友,那么用户应该是他的朋友:
我尝试此查询,但问题是它给出了错误:
#1241 - 操作数应包含1列
有没有办法以不同的方式编写此查询并获得适当的结果。
SELECT `U`.`UserGUID`, `U`.`FirstName`, `U`.`LastName`
FROM (`Users` U)
LEFT JOIN `UserPrivacy` UP ON `UP`.`UserID`=`U`.`UserID`
WHERE `UP`.`PrivacyLabelKey` = 'group_invite'
AND
IF(UP.Value='everyone',true,'')
OR
(UP.Value='network',U.UserID IN(SELECT F2.FriendID FROM Friends F JOIN Friends F2 ON F.FriendID = F2
.UserID WHERE F.UserID = 5 AND F2.Status='1' AND F.Status='1' GROUP BY F2.FriendID),'')
OR
(UP.Value='friend',U.UserID IN(SELECT FriendID FROM Friends WHERE UserID=5 AND Status=1),'')
AND U.UserID!=5
GROUP BY `U`.`UserID`
答案 0 :(得分:1)
试试这个:
SELECT `U`.`UserGUID`, `U`.`FirstName`, `U`.`LastName`
FROM (`Users` U)
LEFT JOIN `UserPrivacy` UP ON `UP`.`UserID`=`U`.`UserID`
WHERE `UP`.`PrivacyLabelKey` = 'group_invite'
AND
IF(UP.Value='everyone',true, IF(UP.Value='network', U.UserID IN(SELECT F2.FriendID FROM Friends F JOIN Friends F2 ON F.FriendID = F2
.UserID WHERE F.UserID = 5 AND F2.Status='1' AND F.Status='1' GROUP BY F2.FriendID), if(UP.Value='everyone',U.UserID IN(SELECT FriendID FROM Friends WHERE UserID=5 AND Status=1),'')))
AND U.UserID!=5
GROUP BY `U`.`UserID`