title: Querying DAU/MAU over time (daily)
body: <p>I have a daily sessions table with columns user_id and date. I'd like to graph out DAU/MAU (daily active users / monthly active users) on a daily basis. For example:</p>
  <pre><code>Date         MAU      DAU     DAU/MAU
  2014-06-01   20,000   5,000   20%
  2014-06-02   21,000   4,000   19%
  2014-06-03   20,050   3,050   17%
  ...          ...      ...     ...
  </code></pre>
  <p>Calculating daily active users is straightforward but calculating the monthly active users e.g. the number of users that logged in today minus 30 days, is causing problems. How is this achieved without a left join for each day?</p>
  <p>Edit: I'm using Postgres.</p>