title: SQL sum after group by
body: <p>I have a query that I built for Volusion, which is very limited in SQL abilities, such as I can't use temp tables, or even variables... which is how I would normally try to do this task.</p>
  
  <p>but, I have this query which gives me the info I need, but I have to work with it in Excel after running... and I'd like to get the query to get me the results I need.</p>
  
  <p>What I ultimately need is the cost/profit by google_gender and by rep... summed.
  Is there a way I can accomplish this without variables or temp tables?</p>
  
  <p>here's my current query:</p>
  
  <pre><code>SELECT
      Products_Joined.Google_Gender,
      REPLACE(REPLACE(REPLACE(REPLACE(Customers.SalesRep_CustomerID,379646,'Dan'),658024,'Owen'),643352,'Mary'),584310,'Pete') as SalesRep,
      SUM(OrderDetails.ProductPrice)*OrderDetails.Quantity as TotalSold,
      SUM(OrderDetails.Vendor_Price)*OrderDetails.Quantity as VendorCost,
      SUM(OrderDetails.ProductPrice)*OrderDetails.Quantity-(OrderDetails.Vendor_Price)*OrderDetails.Quantity as Profit
  FROM
      Products_Joined, OrderDetails, Orders, Customers
  WHERE
      Products_Joined.ProductCode=OrderDetails.ProductCode 
      AND OrderDetails.OrderID=Orders.OrderID 
      AND Orders.CustomerID=Customers.CustomerID
      AND Orders.OrderDate BETWEEN '05/01/16 00:00' and '05/31/16 23:59'
      AND Customers.SalesRep_CustomerID in ('379646' , '658024' , '643352' , '584310')
      AND Orders.OrderStatus &lt;&gt; 'Cancelled'
  GROUP BY    
      Products_Joined.Google_Gender,
      OrderDetails.Quantity,
      OrderDetails.Vendor_Price,
      OrderDetails.ProductPrice,
      Customers.SalesRep_CustomerID
  </code></pre>
  
  <p>because the query has to pull item information from OrderDetails, to get the "sold price" it lines out each order# and sku in the resulting file, which i don't need, I just need the total amount by each google_gender, by rep. and there's only going to be the 4 reps :)</p>