如何正确使用子查询的续集?
...... .....
return myDb.myTable.rollgroup.findAll({
attributes : ['ID','GROUPNAME'],
where : {
id : {
$notIn: ? //// how to use subQuery here
}
}
}).then((getResult) => {
return getResult;
})
.......
.......
我的原始查询像这样:如何正确使用子查询的续集?
从MYGROUP毫克其中mg.ID不
回答:
(?从employeegrouprelation EGR其中egr.PID =选择egr.GROUPID)选择mg.ID,mg.GROUPNAME
您可以使用sequelize.literal的包裹子查询:
... id:{
$notIn: sequelize.literal('(select egr.GROUPID from employeegrouprelation egr where egr.PID = ?)')
}
...
回答:
另一种方式来做到这一点
myDb.myTable.employeegrouprelation.findAll({ attributes: [egr.GROUPID],
where: {
egr.PID: ????
}
}).then((ids) => {
var id = [0]
ids.map((id) => {
id.push(id.GROUPID)
})
return myDb.myTable.rollgroup.findAll({
attributes : ['ID','GROUPNAME'],
where : {
id : {
$notIn: id
}
}
}).then((getResult) => {
return getResult;
})
})
以上是 如何正确使用子查询的续集? 的全部内容, 来源链接: utcz.com/qa/265440.html