title: Make a select with one of the column based on other select and SUM
body: <p>I'm working with windev 17 using the database hyperfile client/serveur.</p>
  
  <p>I have a table named Operation with colums (accountNumber, date, amount, operationType ).</p>
  
  <p>operationType can take two values: "payment" and "withdrawal".</p>
  
  <p>I want to select the List of operations done in an account and, my List should display 5 colums: Date, accountNumber, amount, operationType and balance.</p>
  
  <p>The last column (balance) should be the difference between the sum of all operations done before the current date with type "payment" and the sum of all operation done before the current date with type "withdrawal"</p>
  
  <p>I try the following sql code</p>
  
  <pre><code>SELECT date, accountNumber, operationType, deposits - withdrawals AS balance
  FROM Operations o INNER JOIN (
       SELECT accountNumber, date, SUM(amount) AS withdrawals
       FROM Operaions
       WHERE operationType = 'withdrawal'
       GROUP BY accountNumber
  ) a ON  (o.accountNumber = a.accountNumber AND a.date&lt;=o.date)
  INNER JOIN (
       SELECT accountNumber,date, SUM(amount) AS deposits
       FROM Operations
       WHERE operationType = 'deposit'
       GROUP BY accountNumber
  )b ON (o.accountNumber = b.accountNumber AND b.date&lt;=o.date)
  </code></pre>
  
  <p>but the Query does'nt display any value.</p>
  
  <p>I also tried this one</p>
  
  <pre><code> SELECT date as dateop, accountNumber, operationType, deposits - withdrawals AS balance
  FROM Operations o INNER JOIN (
       SELECT accountNumber, date, SUM(amount) AS withdrawals
       FROM Operaions
       WHERE operationType = 'withdrawal' AND date&lt;=dateop
       GROUP BY accountNumber
  ) a ON  o.accountNumber = a.accountNumber
  INNER JOIN (
       SELECT accountNumber,date, SUM(amount) AS deposits
       FROM Operations
       WHERE operationType = 'deposit' AND date&lt;=dateop
       GROUP BY accountNumber
  )b ON o.accountNumber = b.accountNumber
  </code></pre>
  
  <p>but i'm getting an error telling me that column dateop does not exist.</p>
  
  <p>please i need a help</p>