title: Sequelize.js : Sum with condition and group by
body: <p>I'm a biginner using Sequelize.</p>
  <p>I spend hours trying to get the following code runs but I can't</p>
  <p>I quit some columns from the table for better understanding.</p>
  <p>Finance table</p>
  <p><a href="https://i.stack.imgur.com/I2cYs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I2cYs.png" alt="Finance Table" /></a>
  I want to get this result:</p>
  <pre><code>[
   {
    'month': 11,
    'year': 2021,
    'commission_paid_sum': 2700,
    'comission_notPaid_sum':2500,
   },
   {
    'month': 12,
    'year': 2021,
    'commission_paid_sum': 0,
    'comission_notPaid_sum':1000,
   },
   {
    'month': 1,
    'year': 2022,
    'commission_paid_sum': 2000,
    'comission_notPaid_sum':0,
   },
  ]
  </code></pre>
  <p>I tried:</p>
  <p>1- adding a attribute but I don't get how to add the &quot;where/having condition&quot; in the fn Sum</p>
  <pre><code>db.Finanzas.findAll({
          attributes: ['mes', 'ano','is_paid',
              [Sequelize.fn('sum', Sequelize.col('agents_commission')), 'commission_paid_sum'],
              [Sequelize.fn('sum', Sequelize.col('agents_commission')), 'comission_notPaid_sum'],
  ],
  group: [ 'month' , 'year'],
  </code></pre>
  <p>I've tried also using the literal feature, but in this, I wasn't able to split them by month/year in the result.</p>
  <p>If you think that there was an alternative option, I'll be happy to heard about that.</p>
  <p>Thanks in advance!</p>
  <p>Alejandro</p>