我想在属性中运行一个函数,并使startDate
和endDate
之间有所不同。但是当我执行代码时,出现以下错误:
列“ Signals.id”必须出现在GROUP BY子句中或 用于聚合函数
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;
有人可以帮助我吗?怎么了?!
答案 0 :(得分:0)
摘要函数(MIN,MAX,SUM等)通常需要GROUP BY子句。 MIN和MAX日期字段应应用于什么数据集?每个ID是否会有多个日期?