sequlize通过聚合查询:
const res = await ctx.mode.Record.findAndCountAll({ order: [['createdAt', 'DESC']], group: ['message'] })
但结果是每个组个的第一条,怎么设置才会让group取最后一条呢?
查了下mysql 是 先把数据排序,再查询group。
sequelize不知道怎么?
const res = await ctx.mode.Record.findAndCountAll({ order: [[sequelize.fn('max', sequelize.col('createdAt')), 'DESC'],], group: ['message'] })
548k questions
547k answers
4 comments
86.3k users