title: Group by Week Number and Week Ending
body: <p>I am trying to show sql query by grouping by week number and to show week ending of the week rather beginning of week but thus far have been futile in achieving this. How can I do this?</p>
  
  <pre><code>select extract(week from actual_sale_date) as week_number,
  to_char(date_trunc('week',  actual_sale_date) as date, 'MM/dd/yyyy'), count(*)
  from data
  where project_id = 'ABC'
  and actual_sale_date &gt;= date_trunc('year',current_date)
  group by rollup( (actual_sale_date))
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>week_number        date                 count  
     1             01/02/2017                2
     1             01/02/2017                1                    
     2             01/09/2017                1
     2             01/09/2017                1
     2             01/09/2017                1
     3             01/16/2017                3
     3             01/16/2017                1
                                             10
  </code></pre>
  
  <p>Requested:</p>
  
  <pre><code>week_number                 week_ending                     count 
      1                        01/08/2017                       3
      2                        01/15/2017                       3
      3                        01/22/2017                       4
                                                                10
  </code></pre>