title: Get records of max date for every week in a table
body: <p>I have a table like this:</p>
  
  <pre><code>date     | data
  -----------------
  1/1/2017 | a
  -----------------
  1/2/2017 | b
  -----------------
  1/3/2017 | c
  -----------------
  1/7/2017 | d
  -----------------
  ...
  -----------------
  2/2/2017 | a
  -----------------
  2/2/2017 | b
  -----------------
  </code></pre>
  
  <p>I need to get the data of max date for each week available in the table. The dates can be presented many times, some dates might be missing, and weeks might not be added with all seven days.</p>
  
  <p>The first and probably the easiest solution that comes to mind is something like this:</p>
  
  <pre><code>select maxdate, data from (
  select max(date) as maxdate from mytable group by DATEPART(wk, date)
  ) t1, maytable
  where mytable.date = t1.date
  </code></pre>
  
  <p>But I was told there's a better solution without using max function. Is that even possible? Is there any better way that the above?</p>
  
  <p>This is a hypothetical question and the above query might not be 100% correct as I haven't tested it.</p>