我正在尝试用Knex编写一个UPDATE
语句。
我要输出的SQL是:
UPDATE customers SET "month_value" = "src"."month_value", "modified" = NOW() FROM ( SELECT COALESCE(SUM("month_value"), 0) AS month_value FROM "customer_products" WHERE "active" = true AND "customer_id" = 111781 ) src WHERE "id" = 111781
到目前为止,这是我的JavaScript:
db.knex.table('customers')
.where('id', '=', ':customerId')
.from(db.sequelize.knex.raw('(' +
'SELECT' +
'COALESCE(SUM("month_value"), 0) AS month_value' +
'FROM "customer_products"' +
'WHERE "active" = true' +
'AND "customer_id" = ?' +
') AS src' +
'WHERE "id" = :customerId', [customerId]))
.update({'month_value': src.month_value,
'modified': NOW(),
})
但是,它给了我这个错误:
{"message":"ApiErrorMiddleware ReferenceError: src is not defined","level":"info"}
{"message":"UnknownErrorMiddleware ReferenceError: src is not defined","level":"info"}
我做错了什么?
答案 0 :(得分:0)
这对我有用:
treeId