gpt4 book ai didi

node.js - nodejs sequelize 包括关系排序

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

有拖车模型,一个是船主,另一个是船价格我想要所有的船数据及其价格和按船价降序排列查询没有按预期工作,它在我的关系中的排序数据也显示结果已排序,但它的不接所有船中价格最高的船

db.BoatMaster.findAndCountAll({
distinct: true,
limit:request.params.pagesize,
offset:offsetpage,
attributes:[
'id',
'name',
'saleprice','length','cabins','year','berths','createdAt','updatedAt'
],
include:[
"boat_price",

],
order:[
['boat_price','price','DESC']
],
})

这是查询输出
SELECT 
"BoatMaster".*,
"boat_price"."id" AS "boat_price.id",
"boat_price"."price" AS "boat_price.price",
"boat_price"."boatId" AS "boat_price.boatId",
"boat_price"."currency" AS "boat_price.currency",
"boat_price"."datefrom" AS "boat_price.datefrom",
"boat_price"."dateto" AS "boat_price.dateto"
FROM
(
SELECT
"BoatMaster"."id",
"BoatMaster"."name",
"BoatMaster"."saleprice",
"BoatMaster"."length",
"BoatMaster"."cabins",
"BoatMaster"."year",
"BoatMaster"."berths",
"BoatMaster"."createdAt",
"BoatMaster"."updatedAt"
FROM
"BoatMasters" AS "BoatMaster"
WHERE
(
SELECT
"boatId"
FROM
"boatprices" AS "boat_price"
WHERE
(
"boat_price"."boatId" = "BoatMaster"."id"
)
LIMIT
1
) IS NOT NULL
LIMIT
10 OFFSET 0
) AS "BoatMaster"
INNER JOIN "boatprices" AS "boat_price" ON "BoatMaster"."id" = "boat_price"."boatId"
ORDER BY
"boat_price"."price" DESC;

任何人都可以帮助我解决我在这里做错了什么,因为数据没有根据价格进行排序?
提前致谢

最佳答案

试试这个(如果正确):

 include:[
boat_price,

],
order:[
[boat_price,'price','DESC']
],

或者
 include:[
boat_price,

],
order:[
['boat_price.price','DESC']
],

关于node.js - nodejs sequelize 包括关系排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58297758/

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