title: Aggregating data in a table up to the date of each row in the table
body: <p>If I run the following query, it results in 1.6M rows:</p>
  
  <pre><code>SELECT 
      customer_id,
      credit_id,
      date
  FROM 
      wallet
  WHERE
      credit_title = 'Topups'
      AND credit_type = 'Credit Card Topups'
      AND day &gt;= DATE '2017-11-06'
      AND day &lt;= DATE '2020-04-03'
  </code></pre>
  
  <p>I am now trying to, for each row in the above query, get the count and total amount of all credit transactions for that customer up to the date of the row. I have tried the below query (which is a join with itself), but this results in 1.3M rows. Why are rows being dropped in the join? <code>credit_id</code> is a unique identifier in this table.</p>
  
  <pre><code>SELECT
      customer_id,
      credit_id,
      COALESCE(COUNT(wallet_agg.credit_id), 0) AS topup_count_to_date,
      COALESCE(SUM(wallet_agg.credit_amt_usd), 0) AS topup_amount_to_date
  FROM
      wallet
  LEFT JOIN
      wallet AS wallet_agg
  ON
      wallet.customer_id = wallet_agg.customer_id
      AND wallet_agg.date &lt; wallet.date
  WHERE
      wallet.credit_title = 'Topups'
      AND wallet.credit_type = 'Credit Card Topups'
      AND wallet.day &gt;= DATE '2017-11-06'
      AND wallet.day &lt;= DATE '2020-04-03'
      AND wallet_agg.credit_title = 'Topups'
      AND wallet_agg.credit_type = 'Credit Card Topups'
  </code></pre>
  
  <p><a href="https://www.db-fiddle.com/f/4asLLA1FRAeXKa8c6NRKii/4" rel="nofollow noreferrer">Here is a simple demo of what I am trying</a>, which gets the result I am expecting. How is the logic of my more complex query above different?</p>