我有以下疑问:
select coalesce(round(sum(vdamesatual) /
(select count(*)
from feriados
where month(data)=month(current_date) and
day(data)<day(current_date) and
diadasemana in(2,3,4,5,6) and
feriadonacional=0 and
uf <> (select distinct uforigem from baseprodutos where Empresa = 'test'))
*
(select count(*)
from feriados
where month(data)=month(current_date) and
day(data)>=day(current_date) and
diadasemana in(2,3,4,5,6) and
feriadonacional=0 and
uf <> (select distinct uforigem from baseprodutos where Empresa = 'test'))),0) as projecao
from baseprodutos
where Empresa = 'test' and
UFDest = 'uf' and
Fabricante = 'sample';
正如你所看到的,我在第一次选择之后有一个合并,我很难找到正确的方法来用sequelize写这个;你有什么建议吗?
1条答案
按热度按时间t5fffqht1#
我并不真正遵循您的查询逻辑,但是sequelize中的规则是您可以使用
sequelize.fn()
因此,在sequelize中使用coalesce从带有别名的两列中获取值的简单示例如下所示attributes
:如果需要,可以包含另一个函数,例如
SUM
这样做: