title: MySQL WHERE by AS Statement
body: <p>My Tables</p>
  
  <pre><code>Table1 :
  ___________________________________
  | ID | UserID | Amount | Date     |
  ___________________________________
  | 1  | 1      | 10     | 2014-12-10
  | 2  | 1      | 5      | 2014-12-12
  | 3  | 2      | 50     | 2014-12-12
  
  Table2 :
  _________________________________________________
  | ID | UserID | Amount | Description  | Date     |
  _________________________________________________
  | 1  | 2      | 50     | Test Payment | 2014-12-10
  </code></pre>
  
  <p>I want the user to calculate the balance. And i use this MySQL code</p>
  
  <pre><code>SELECT
  Distinct(UserID) As User,
  (SELECT COALESCE(SUM(Amount),0) FROM Table1 WHERE UserID=User) AS Credit,
  (SELECT COALESCE(SUM(Amount),0) FROM Table2 WHERE UserID=User) AS Received,
  ((SELECT COALESCE(SUM(Amount),0) FROM Table1 WHERE UserID=User) - (SELECT COALESCE(SUM(Amount),0) FROM Table2 WHERE UserID=User) As Balance
  FROM Table1 WHERE Balance&gt;0
  </code></pre>
  
  <p>but i can't where by as statement.</p>