我想将sql转换为sequelize函数
我尝试过代码
const result = await models.chapter.findOne({
logging: log.trace,
where: {
seq: db.fn('max', db.col('seq'))
}
});
SQL中的成功代码
select * from page_chapter where seq = (select max(seq) from page_chapter)
我希望得到
这样的结果 const result = await model.chapter.findOne({
where: {
seq: sequelize.fn('max', sequelize.col('seq'))
}
})
答案 0 :(得分:0)
您可以使用sequelize.literal
来获取查询:
const result = await model.chapter.findOne({
where: sequelize.literal('"seq" = (SELECT MAX("page_chapter"."seq") FROM "page_chapter")')
})