elainetian3 2016-03-28 07:41 采纳率: 25%
浏览 1709
已采纳

求助MySQL的关于sql语句怎么写??三表的查询~~~请大神进来帮忙~~~~~

现在我有三个表:
表1:
pre_common_member_profile:
uid(用户的uid),
gender(性别),
birthyear(出生的年),
birthmonth(出生的月),
birthday(出生的日)
表2:
pre_home_friend:
uid(用户的uid),
fuid(加为好友的uid)
表3:
pre_home_friend_request:
fuid(发送好友请求的人),
uid(发送给谁)

要求:
查找表1,但是排除一定条件。

查询表1上面的五个字段,条件为uid=570并且uid不能等于(这两个条件:1、表2中uid=570的fuid的值。2、表3中的fuid=570的uid值。)

请尽量写出的语句效率高一点。

  • 写回答

7条回答 默认 最新

  • elainetian3 2016-03-28 08:07
    关注

    @bdmh
    select gender,uid,birthmonth,birthday,birthyear from pre_common_member_profile as p where destination = '济南' and p.uid <> 570 and p.uid < 570 and gender = 0 and uid not in(select fuid from pre_home_friend where uid=570 union select uid from pre_home_friend_request where fuid = 570) order by uid desc
    怎么优化一下??

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作