我想使用主键运行结果排序查询,并限制返回结果的数量。例如:return Things.findAll({
attributes: [
'id',
'status',
'otherField'
],
limit: 2,
order: [['id', 'DESC']]
})
构建查询时,它会生成以下 SQL 语句:... ORDER BY [Source].[id] DESC, [id] OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY
因为 id
是主键并且排序参数也是 id
我收到以下错误:'A column has been specified more than once in the order by list. Columns in the order by list must be unique.'
我正在使用 sequelize 3.30.4 和乏味的 2.0.0 连接到 Microsoft SQL Server 2017。
谢谢你。
最佳答案
顺序数组应包含数组/元组。试试这个:
return Things.findAll({
attributes: [
'id',
'status',
'otherField'
],
limit: 2,
order: [
['id', 'DESC']
]
})
关于sql-server - Sequelize mssql : order by primary key and limit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45868651/