业务背景
一个学校有很多老师
每个老师都教很多不同的班
现在要找出同时教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暂时没弄