title: Illuminate database query with date_sub
body: <p>I'm struggling with a query using the Illuminate database query builder.
  When I use the query the result is not as I expected.
  When using the query from the querylog directly with mysql cli, I get the expected result.</p>
  
  <p>With query builder:</p>
  
  <pre><code>    -&gt;table('CompanyTools')
      -&gt;select(
          'CompanyTools.toolId', 
          $db-&gt;raw('COUNT(CompanyTools.toolId) as count')
      )
      -&gt;whereYear('CompanyTools.date', '&gt;', 'YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))')
      -&gt;groupBy('CompanyTools.toolId')
      -&gt;orderBy('count', 'DESC')
      -&gt;take(1)
      -&gt;get();
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Array ( [toolId] =&gt; 88 [count] =&gt; 55 )  
  </code></pre>
  
  <p>With mysql cli:</p>
  
  <pre><code>select `CompanyTools`.`toolId`, COUNT(CompanyTools.toolId) as count from `CompanyTools` 
  where year(`CompanyTools`.`date`) &gt; YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)) 
  group by `CompanyTools`.`toolId` 
  order by `count` desc 
  limit 1
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>ToolId: 88
  count: 17
  </code></pre>
  
  <p>If I (in the query builder) replace <code>'YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))'</code>with <code>2013</code> I get:</p>
  
  <pre><code>Array ( [toolId] =&gt; 88 [count] =&gt; 17 )  
  </code></pre>
  
  <p>Somehow the date_sub get ignored so the result includes all years</p>
  
  <p>I tried with <code>-&gt;whereYear('CompanyTools.date', '&gt;', $db-&gt;raw('YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))'))</code> without any luck.</p>
  
  <p>I guess I could use php to calculate the desired year, but I would rather get the query right.</p>
  
  <p>Thx in advance</p>
  
  <p>/ j</p>
  
  <p>UPDATE</p>
  
  <p>Replacing</p>
  
  <pre><code>-&gt;whereYear('CompanyTools.date', '&gt;', 'YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))')
  </code></pre>
  
  <p>with</p>
  
  <pre><code>-&gt;where($db-&gt;raw('YEAR(CompanyTools.date)'), '&gt;', $db-&gt;raw('YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))'))
  </code></pre>
  
  <p>solves it. Not clever enough to figure out why, but perhaps the whereYear function is supposed to be used diffently</p>