I need to convert this SQL to Sequelize. I'm new here and I can't convert it. I have Error on [tem_interesse], the rest works, but i don't know how to convert it, can someone show me the process to convert? Thank you
select distinct
aux.nome,
aux.media,
case when fi.idfuncionario is not null
then 1
else 0 end [tem_interesse]
from {
select e.nome, e.id, round(avg(fc.nivelcomp), 2) as media
from employee e
inner join funcionarios_competencias fc on fc.idfuncionario = e.id
where fc.idcompetencia in (1,3)
group by e.nome, e.id
}aux
left join funcionarios_interesses fi on fi.idfuncionarios = aux.id and fi.idinteresse in (1,2)
where aux.media is not null
order by aux.media desc, [tem_interesse] desc
limit 3