SELECT
users.id,SUM(b)
FROM
users LEFT JOIN c
on c.d like CONCAT(users.d,'%')
GROUP BY users.id
1
zbinlin 2019-11-14 18:04:55 +08:00
应该没问题
|
2
wangyzj 2019-11-14 18:14:23 +08:00
可以
|
3
sys234 2019-11-14 20:24:58 +08:00 1
```javascript
//tableName=>Model //users=>Users; c=>ModelC Users.findAll({ attributes: ["id", [fn("SUM", col("b")), "aliasB"]], include: [{ association: Users.belongsTo(ModelC, { foreignKey: "d" }), model: ModelC, attributes: [], required: false, on: { d: { [Op.like]: fn("concat", literal("users.d"), "%") } } }], group: [literal("users.id")], limit: 10 }).then(result => { console.log(JSON.stringify(result)); }).catch(err => { }); ``` |