title: Equation needing to be in a group by statement?
body: <p>I have been getting this error:</p>
  
  <blockquote>
    <p>Column 'dbo.MainDB.Packaging Quantity' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p>This problem came up after I added the equation for Total and I have attempted to add aggregate functions to the equation, but it just gives me the wrong output if I add any.  Also, if I add it to the group by clause then it adds unnecessary groups, does anyone know a solution?</p>
  
  <p>Code:</p>
  
  <pre><code>SELECT 
      CONVERT(varchar,shipdate,101) AS Shipdate,
      ID, 
      [Last Name], 
      Address,
      SUM([Packaging Quantity]) AS Quantity,
      Size, 
      SUM(Cost) AS Price,
      ROUND(Size/[Packaging Quantity], 0) AS Total
  FROM dbo.MainDB
  WHERE 
      Shipdate BETWEEN '09/01/2019' AND '09/30/2019 11:59:59PM'
      AND Cost &lt;&gt; '0'
  GROUP BY   
      CONVERT(VARCHAR, shipdate, 101),
      ID,
      [First Name],
      Address,
      Size
  </code></pre>