dongyu2764 2015-11-02 11:48
浏览 49
已采纳

检查隐私并在单个查询中根据它获取用户

I have write a query in which I'm checking if user set his privacy to everyone it will return that result, if user sets to network then current user in my case its 5 will check that user must be his friend or friend of friend and if its set to friend then user should be his friend:

I try this query but issue is its giving an error:

#1241 - Operand should contain 1 column(s)

is there any way to write this query in different way and get appropriate result.

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`
  • 写回答

1条回答 默认 最新

  • douhaodang0403 2015-11-02 12:48
    关注

    try this :

    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`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?