title: Use a calculated column in a where clause
body: <p>I'm trying to use a calculated column in a where clause.</p>
  
  <p>I've trying everything from CROSS APPLY, to sub-query select but it does not give me the anything near what I need.</p>
  
  <p>My query so far:</p>
  
  <pre><code>SELECT p.Code, c.AccountNumber, Sales = (SUM(p.UnitPrice) * SUM(od.QtyShipped)) FROM [dbo].Customer c 
      LEFT JOIN [dbo].OrderHeader oh ON oh.CustomerId = c.Id 
      LEFT JOIN [dbo].OrderDetail od ON od.OrderHeaderId = oh.Id
      LEFT JOIN [dbo].Product p ON p.Id = od.ProductId
  WHERE Sales &gt; 100
  GROUP BY p.Code, c.AccountNumber, Sales
  </code></pre>
  
  <p>This does not work, as 'Sales' is an invalid column</p>