gpt4 book ai didi

sql-server - Sequelize mssql : order by primary key and limit

转载 作者:行者123 更新时间:2023-12-03 22:17:38 25 4
gpt4 key购买 nike

我想使用主键运行结果排序查询,并限制返回结果的数量。例如:
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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com