title: Sequelize get data of another column while using Aggregate Function
body: <p>I'm trying to get data using <strong>Sequelize</strong> in my <strong>Express</strong> app and I'm using <strong>SQL Server</strong> as database.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Order.findAll({
      attributes:[
          [Sequelize.fn('SUM', Sequelize.col('total_price')), 'total_price'],
      ],
      include:[
          {model: Customer, attributes:['name']}
      ],
      group:['Customer.id','Customer.name']
  }).then(result =&gt;res.json(result))
  </code></pre>
  
  <p>This code is running well, and successfully returns the data with <em>aggregate function</em>. But when I did added another attribute like <code>'product_id', 'status', 'expired_date'</code> that doesn't need aggregation, it returns me an error like</p>
  
  <blockquote>
    <p>Column 'Customer.product_id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p>Based on this <a href="https://www.codeproject.com/Articles/1110163/SQL-GROUP-By-and-the-Column-name-is-invalid-in-the" rel="nofollow noreferrer">article</a>, it only can get columns which are in the GROUP BY list.</p>
  
  <p>But how is the best way get the added attribute and the aggregation result? Like:</p>
  
  <pre><code>{
       'total_price': 2000,
       'name': 'Jack',
       'status': 'Paid'
  }
  </code></pre>
  
  <p>Should do 2 get data in a function, like first I get the aggregate, and then get another data. I'm worried there are possibilities return unrelated data.</p>