title: Use alias name in same query for SQL Server
body: <p>When performing a SQL Query with using an alias on a column name, I am trying to reference that alias in the same query to perform a calculation on it.</p>
  
  <p>Such as:</p>
  
  <pre><code>SELECT QUANTITY, 
         AMOUNT, 
         Count(AMOUNT) AS CntAmount, 
         Sum(CNTAMOUNT) 
  FROM   MY_TEST 
  GROUP  BY QUANTITY, 
            AMOUNT 
  </code></pre>
  
  <p>This query is just an example.</p>
  
  <p>I thought you normally reference the query as an alias but that didn't work. Such as:</p>
  
  <pre><code>SELECT * 
  FROM   (SELECT QUANTITY, 
                 AMOUNT, 
                 Count(AMOUNT) AS CntAmount, 
                 Sum(A.CNTAMOUNT) 
          FROM   MY_TEST 
          GROUP  BY QUANTITY, 
                    AMOUNT) a 
  </code></pre>