title: Group by week in MySQL
body: <p>Table structure is,</p>
  
  <pre><code>Table name: btq_user
  
  name, email, kall, state_id, datain
  </code></pre>
  
  <p>Now i want to count number records which has kall = 1 or state_id in( 51, 20, 46) by weekly.
  i need the results only by weekly (Mon - Sun) no matter if year changes. lets say for example 31-12-2012 is Monday and 6-1-2013 is Sunday so result should include that as a week. no matter if year changes it should count only with weeks.</p>
  
  <p>This is what i tried but not working.</p>
  
  <pre><code>SELECT 
  count( if( A.state_id = 51 or A.state_id = 20 or A.state_id = 46, A.state_id,
  null  ) ) AS state_total, count( if( A.kall =1, A.kall, null ) ) AS appointment, 
  CONCAT( WEEK( A.datain) , " - 
  ", YEAR( A.datain ) ) AS week
  FROM btq_user A
  GROUP BY week
  ORDER BY A.datain ASC
  </code></pre>
  
  <p>also is there any possibility to display weeks ( 31-12-2012 - 6-1-2013 ) with results ?</p>
  
  <p>Thank you for reading my question.</p>