title: Get week over week data
body: <p>I have a table as follows </p>
  
  <pre><code>CREATE TABLE messages  ( 
  id          int(10) UNSIGNED AUTO_INCREMENT NOT NULL,
  messagetext text NOT NULL,
  created_at  timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY(id)
  </code></pre>
  
  <p>)</p>
  
  <p>What I would like to do is to get two weeks of data, the current week and the previous week, ordered by days. For example how many messages were created on Sunday, Monday, Tuesday,Wednesday.... for this week and the last week. </p>
  
  <p>I do have a query as follows </p>
  
  <pre><code>SELECT
      COUNT(id) AS 'Count' 
  FROM
      'messages'
  WHERE
      (WEEK(created_at) = WEEK(NOW())) 
  GROUP BY
      WEEKDAY(created_at) 
  ORDER BY
      week(created_at) ASC,
      weekday(created_at) ASC
  </code></pre>
  
  <p>but I don't know how to sort it day wise. For example the query above will list me how many did i get today or yesterday but that is not what what I want. What I would like to have is to get the count day wise as well as week wise. </p>
  
  <p>Here is what I would like to have 
  <a href="https://i.stack.imgur.com/JQ3m4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JQ3m4.png" alt="enter image description here"></a></p>
  
  <p>Please let me know if i clear enough with the situation that I am facing. </p>
  
  <p><strong>Update:</strong>
  For more information , please see Juan's question below </p>
  
  <p>If the current days are less that 14 days , in that case, the script should return the count for the days that are in the previous week , not the week before the previous week. Here is how Juan explained (imagine today is friday. if you count 14 day back you get this week monday to friday. previous week monday to sunday... and prev prev week friday to sunday. And not sure if that is the result you want) </p>
  
  <p>With Regards</p>
  
  <p>Gagan</p>