......
.....

return myDb.myTable.rollgroup.findAll({

                attributes : ['ID','GROUPNAME'],
                where : {
                    id : {
                      $notIn: ? //// how to use subQuery here
                    }
                }


              }).then((getResult) => {

                  return getResult;

              })
.......
.......

我的原始查询是这样的:

select mg.ID,mg.GROUPNAME from mygroup mg where mg.ID not in (select egr.GROUPID from employeegrouprelation egr where egr.PID = ? )

最佳答案

您可以使用 sequelize.literal 来包装子查询:

    ...

    id:{
        $notIn: sequelize.literal('(select egr.GROUPID from employeegrouprelation egr where egr.PID = ?)')
       }

    ...

关于node.js - 如何在 sequelize 中正确使用子查询?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47993257/

10-09 22:20