账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    [已解决]sql外键表关联查询的一个问题
    32
    0

    业务背景

    一个学校有很多老师
    每个老师都教很多不同的班
    现在要找出同时教1,2,3班的老师

    环境

    node.js+sequelize+mysql

    表结构

    • 老师表:teacher(id,name)
    • 班级表:class(id,name)
    • 老师班级表:teacher_class(id,teacherId,classId)

    问题

    sql语句怎么查呢?
    sequelize中怎么用呢?

    尝试

    select teacherId from teacher_class where classId in [1,2,3]
    //这个连只教1班的也会查出来
    select teacherId from teacher_class where classId = 1 and classId =2 and classId =3
    //这个显然不可能

    已解决

    sql里面分组后再筛选,sequelize暂时没弄
    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 浪子边城 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部