postgresql – 如何使用Sequelize查询两列是否相等?

前端之家收集整理的这篇文章主要介绍了postgresql – 如何使用Sequelize查询两列是否相等?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
db.WorkbookQuestion.count({
  where: {
    QuestionId: dbQuestion.id,AnswerSelectedId: db.sequelize.col('CorrectAnswerId')
  }
});

查询生成sql:SELECT count(*)AS“count”FROM“WorkbookQuestions”AS“WorkbookQuestion”WHERE“WorkbookQuestion”.“QuestionId”= 1103 AND“CorrectAnswerId”;

我如何让它更像AnswerSelectedId = CorrectAnswerId?

你可以通过sequelize.where()来做到这一点:
db.WorkbookQuestion.count({
  where: sequelize.where(
    db.sequelize.col('CorrectAnswerId'),db.sequelize.col('AnswerSelectedId')
  )
});
原文链接:https://www.f2er.com/postgresql/191854.html

猜你在找的Postgre SQL相关文章