let children = models.StatsFusionEvent.findAll({
attributes: [['event_type', 'eventType'],
[sequelize.fn('sum', sequelize.col('count')), 'count'],
sequelize.literal('sum(case when status = \'FAIL\' then `count` else 0 end) as \'failCount\''),
sequelize.literal('sum(case when status = \'SUCCESS\' then `count` else 0 end) as \'mergeCount\'')
],
raw: true,
group: ['eventType']
});
条件嵌套
let whereCond = {};
let tempSQL = 'select id from `table` where value!=0';
_.extend(whereCond, {
id: {
$notIn: Sequelize.literal('(' + tempSQL + ')')
}
});
字面量查询
自增自减
case 使用
条件嵌套
having
Where clause for left column in LEFT OUTER JOIN
references:
through相关
不查找关联表字段
关联表过滤
一对多关联 (hasMany)
比如series表的外键case_uuid关联case表的uuid,而非主键。即在不同的列上关联记录,您可以使用
sourceKey
选项。Sequelize with NodeJS can't join tables with limit
https://stackoverflow.com/questions/26021965/sequelize-with-nodejs-cant-join-tables-with-limit
sub-query in where conditions
findAndCountAll distinct with include but without include.where condition
https://github.com/sequelize/sequelize/issues/2713