title: Mssql The repetition value of the 2 tables?
body: <p>I want write query to do below result but my query doesn't work.</p>
  
  <hr>
  
  <pre><code>    Table A
  
      code    |    date
      -------------------------------------
      3            2015-01-26
  
      4            2015-01-27
  
      5            2015-01-27
  
      6            2015-01-26
  
      8            2015-01-26
  </code></pre>
  
  <hr>
  
  <pre><code>Table B
  
  code    |    Code B
  -------------------------------------
  3            12
  
  3            10
  
  5             3
  
  6            10
  
  6            12
  
  8            12
  </code></pre>
  
  <hr>
  
  <pre><code>Results
  
  code B    |    value_Repetition 
  -------------------------------------
  12                   3
  
  10                   2
  
  3                     1
  </code></pre>
  
  <hr>
  
  <p>My query</p>
  
  <pre><code>DECLARE @ddd int
  
  select @ddd = code FROM Table A where date between '2015-01-01' and '2015-01-27'
  
  SELECT       code B ,COUNT(code B) AS value_Repetition 
      FROM     Table B
      where code = @ddd
      GROUP BY code B
      ORDER BY value_Repetition  DESC
  </code></pre>