如何使用sequelize.fn(['if'])?

时间:2016-10-15 08:52:44

标签: sequelize.js

例如:已执行(默认):

SELECT if(`evaluates`.`all`, 'good','notgood') AS `sign`, count(*) AS `count` FROM `evaluates` AS `evaluates` WHERE `evaluates`.`deleted_at` IS NULL GROUP BY `sign`;

await DBC.evaluates.count({
        attributes: [[DBC.sequelize.fn(['if'],
        DBC.sequelize.col("`evaluates`.`all`"), ["good", "notgood"]), 'sign']],
        group: ["sign"]
    });

但执行(默认):

 SELECT if(`evaluates`.`all` > 3, 'good','notgood') AS `sign`, count(*) AS `count` FROM `evaluates` AS `evaluates` WHERE `evaluates`.`deleted_at` IS NULL GROUP BY `sign`;

如何?

await DBC.evaluates.count({
        attributes: [[DBC.sequelize.fn(['if'], DBC.sequelize.col("`evaluates`.`all` > 3"), ["good", "notgood"]), 'sign']],
        group: ["sign"]
    });?

这是假的。

1 个答案:

答案 0 :(得分:1)

literal(“evaluatesall> 3”)