将CASE语句转换为Sequelize

时间:2019-04-10 09:04:30

标签: node.js sequelize.js aggregate-functions

我有具有票务状态的票务系统。我想做sequelize查询,将返回各自的状态计数。下面是可以正常工作的原始查询,我想将其转换为续集。

invoice_count

我尝试了let querydata = `SELECT count(*) as total, sum(case when status = 'Allocated' then 1 else 0 end) as allocated, sum(case when status = 'RemindMe' then 1 else 0 end) as remindme, sum(case when status = 'Close' then 1 else 0 end) as closed FROM ticketnotifications WHERE createdby = '` + req.auth.credentials.email + `';`; return ticketdb.sequelize.query(querydata, { type: Sequelize.QueryTypes.SELECT }) .then((agentCountResult) => { return res(agentCountResult[0]); }).catch((err) => { logger.error('agentCount exception...', err); return res(boom.expectationFailed(err)); }); 及其工作原理,但是我一直坚持如何在[Sequelize.fn('COUNT', Sequelize.col('id')), 'total']语句上方进行后续转换。有想法吗?

0 个答案:

没有答案