title: Translating my query from using aggregate functions to using window functions
body: <p>I have a table (<code>wallet_credit_details</code>) where each row is a single transaction made by a single customer. There is another table (<code>wallet_usage_details</code>) which shows how each user paid for these transactions. What I would like to do is - for each row (transaction) in the first table, aggregate (count and sum) values by the customer from the second table up to the date of the transaction in the first table.</p>
  
  <p>An example of this would be for each transaction, count the number of previous transactions by the same customer which we paid for using "Topups".</p>
  
  <pre><code>SELECT
      wallet.customer_id,
      wallet.credit_id AS transaction_id,
      COALESCE(COUNT(usage.debit_id), 0) AS transactions_paid_count_to_date,
      COALESCE(SUM(usage.used_amt_usd), 0) AS transactions_paid_amount_to_date,
      COALESCE(COUNT(CASE WHEN usage.credit_title = 'Topups' AND usage.credit_type = 'Credit Card Topups' THEN 1 END), 0) AS topups_used_count_to_date,
      COALESCE(SUM(CASE WHEN usage.credit_title = 'Topups' AND usage.credit_type = 'Credit Card Topups' THEN usage.used_amt_usd END), 0) AS topups_used_amount_to_date
  FROM
      prod_dwh.wallet_credit_details AS wallet
  LEFT JOIN
      prod_dwh.wallet_usage_details AS usage
  ON
      wallet.customer_id = usage.user_id
      AND usage.transaction_date &lt; wallet.day
  WHERE
      wallet.credit_title = 'Topups'
      AND wallet.credit_type = 'Credit Card Topups'
      AND wallet.day &gt;= DATE '{min_date}'
      AND wallet.day &lt;= DATE '{max_date}'
  GROUP BY
      wallet.customer_id,
      wallet.credit_id   
  </code></pre>
  
  <p>How can I reproduce the same logic using a window function?</p>