I am getting following error : not a valid attribute definition in sequelize

I am getting following error : not a valid attribute definition in sequelize

我如何使用 sequelize 按 desc 按电子邮件顺序获取 COUNT 和后续列组。我收到以下错误:不是有效的属性定义。

const data = await NominationModel.findAll({属性: ['email', 'nomineename',[sequelize.fn('COUNT', sequelize.col( 'email'))]] });

我正在尝试使用 sequelize 低于 sql 查询。

SELECT COUNT(1),nomineename, email FROM devchoice.nominations GROUP BY (email) order by email desc

你好像错过了sequelize中的group,试试这个:

NominationModel.findAll({
    group: ['email', 'nomineename'],
    attributes: ['email', 'nomineename', [sequelize.fn('COUNT', sequelize.col('email')), 'count']],
    order: [
        [Sequelize.literal('count'), 'DESC']
    ],
    raw: true
}).then((rst) => {
    console.log('rst' ,rst);
}).catch((err) => {
    console.log('err', err);
})