title: How to group by week in postgresql
body: <p>I've a database table <code>commits</code> with the following columns: </p>
  
  <blockquote>
    <p>id | author_name | author_email | author_date (timestamp) |
    total_lines</p>
  </blockquote>
  
  <p>Sample contents are: </p>
  
  <pre><code>1 | abc | abc@xyz.com | 2013-03-24 15:32:49 | 1234
  2 | abc | abc@xyz.com | 2013-03-27 15:32:49 | 534
  3 | abc | abc@xyz.com | 2014-05-24 15:32:49 | 2344
  4 | abc | abc@xyz.com | 2014-05-28 15:32:49 | 7623
  </code></pre>
  
  <p>I want to get a result as follows: </p>
  
  <pre><code>id | name | week | commits
  1  | abc  | 1    | 2
  2  | abc  | 2    | 0
  </code></pre>
  
  <p>I searched online for similar solutions but couldnt get any helpful ones. </p>
  
  <p>I tried this query: </p>
  
  <pre><code>SELECT      date_part('week', author_date::date) AS weekly,
          COUNT(author_email)           
  FROM        commits
  GROUP BY    weekly
  ORDER BY weekly
  </code></pre>
  
  <p>But its not the right result. </p>