联表多条件查询SQL编写
发布于 3 年前 作者 leijing 5073 次浏览 来自 分享
db.collection('student')
.aggregate()
.match({
sex: 1
})
.lookup({
from: 'teacher',
let:{
teacherId: '$teacherId'
},
pipeline: $.pipeline()
.match(_.expr($.and([
$.eq(['$teacherId', '$$teacherId']),
$.eq(['$studentName', '捌玖'])
]))).done(),
as: 'dataList'
})
.end()

student 表与 teacher 表关联查询,条件:student.studentName=‘捌玖’ and teacher.sex=1

回到顶部