Node.js 如何正确编写此查询
我试图在Sequelize中执行此查询,但出现错误 质疑 错误Node.js 如何正确编写此查询,node.js,typescript,postgresql,sequelize.js,Node.js,Typescript,Postgresql,Sequelize.js,我试图在Sequelize中执行此查询,但出现错误 质疑 错误 您有两个选项,但首先必须回答这个问题:您是否需要在查询中使用列invoiceId 如果您的答案是肯定的,请尝试: LineItem.findAll({ 属性:['orderId',[fn('sum',col('quantity'),'quantity']], 包括:[ { 型号:订单, 作为:“行项目”, 属性:['invoiceId'], }, ], 组:['orderId','invoiceId'], raw:是的, });
您有两个选项,但首先必须回答这个问题:您是否需要在查询中使用列
invoiceId
如果您的答案是肯定的,请尝试:
LineItem.findAll({
属性:['orderId',[fn('sum',col('quantity'),'quantity']],
包括:[
{
型号:订单,
作为:“行项目”,
属性:['invoiceId'],
},
],
组:['orderId','invoiceId'],
raw:是的,
});
如果您的答案是“否”,请尝试:
LineItem.findAll({
属性:['orderId',[fn('sum',col('quantity'),'quantity']],
包括:[
{
型号:订单,
作为:“行项目”,
},
],
组:['orderId'],
raw:是的,
});
您能否将相关模型添加到问题中?此答案是否解决了您的问题?请接受这个答案,这将帮助其他人。是的,我想要invoiceId列,所以我尝试了第一个选项,但它说“invoiceId”列不存在。您可以发送表和模型的脚本吗?我需要了解你的结构。
LineItem.findAll(
{
attributes: [
"orderId",
[fn("sum", col("quantity")), "quantity"]
],
include: [{
model: Order,
as: "lineItems",
attributes: ["invoiceId"]
}],
group: ["orderId"],
raw: true
});
column \"lineItems.invoice_id\" must appear in the GROUP BY clause or be used in an aggregate function