gpt4 book ai didi

node.js - Sequelizejs 在列上运行函数时出错 - check_ungrouped_columns_walker in

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

我想在属性中运行一个函数并在 startDateendDate 之间获得不同。但是当我执行代码时出现此错误:

column "Signals.id" must appear in the GROUP BY clause or be used in an aggregate function


const lastData = await psql.Signals.findAll({
attributes: [
"id",
"strategy",
"type",
"symbol",
"name",
"timeframe",
"status",
"startDate",
"endDate",
[
Sequelize.literal('EXTRACT(DAY FROM MAX("startDate")-MIN("endDate"))'),
"DateDifference"
],
"positionsData"
],
where: {
isMain: true,
strategy: {
[Op.in]: ["21", "22"]
}
},
order: [["id", "DESC"]],
limit: 50,
raw: true
})

Sequelizejs 预期的 SQL 代码是:
SELECT "id", "strategy", "type", "symbol", "name", "timeframe", "status", "startDate", "endDate", EXTRACT(DAY FROM MAX("startDate")-MIN("endDate")) AS "DateDifference", "positionsData" FROM "signals" AS "Signals" WHERE "Signals"."isMain" = true AND "Signals"."strategy" IN ('21', '22') ORDER BY "Signals"."id" DESC LIMIT 50;

有谁能够帮我?怎么了?!

最佳答案

汇总函数(MIN、MAX、SUM 等)通常需要 GROUP BY 子句。 MIN 和 MAX 日期字段应应用于哪组数据?每个 id 会有多个日期吗?

关于node.js - Sequelizejs 在列上运行函数时出错 - check_ungrouped_columns_walker in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55888996/

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