title: Documents read per user per day
body: <p>I have the following table:</p>
  
  <pre><code>user_id    document_id    date
  ------------------------------------
  1           1             2016-01-01
  1           2             2016-01-01
  1           3             2016-01-02
  2           4             2016-01-01
  2           5             2016-01-02
  3           6             2016-01-02
  3           7             2016-01-02
  3           8             2016-01-02
  3           9             2016-01-03
  3          10             2016-01-03
  3          11             2016-01-04
  3           9             2016-01-04
  </code></pre>
  
  <p>I would like to have an overview: (a) for each day in the table (b) how many documents have been read per user, as follows:</p>
  
  <pre><code>date          user_id    document_count
  ---------------------------------------
  2016-01-01    1          2
  2016-01-01    2          1
  2016-01-01    3          0
  2016-01-02    1          1
  2016-01-02    2          1
  2016-01-02    3          3
  2016-01-03    1          0
  2016-01-03    2          0
  2016-01-03    3          2
  2016-01-04    1          0
  2016-01-04    2          0
  2016-01-04    3          2
  </code></pre>
  
  <p>I only know how to get a result like (1) documents per day or (2) users per day by grouping by date and do a count on the other. But here I have to group by user AND date, and I don't know how to do this.</p>
  
  <p>For learning purposes, how could I achieve also the following, related, result? It would probably require a different grouping order, but I am unsure.</p>
  
  <pre><code>user_id    date         document_count
  --------------------------------------
  1          2016-01-01   1
  1          2016-01-02   1
  1          2016-01-03   0
  1          2016-01-04   0
  2          2016-01-01   1
  2          2016-01-02   1
  2          2016-01-03   0
  2          2016-01-04   0
  3          2016-01-01   0
  3          2016-01-02   3
  3          2016-01-03   2
  3          2016-01-04   2
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>