title: Static drupal 7 query to dynamic query
body: <p>I need to take agent_name, count(id), ifs_code, area_code.</p>
  <p>When I use static query all work fine:</p>
  <pre><code>$result = db_query('SELECT agent_name, count(id) as count, ifs_code, area_code FROM declarations WHERE fisccode = :idno GROUP BY agent_name', array(':idno' =&gt; $fisccode))-&gt;fetchAll();
  </code></pre>
  <p>Result from this query:</p>
  <pre><code>/report5.inc:82: array (size=1) 0 =&gt; object(stdClass)[10] public 'agent_name' =&gt; string 'GHEOLARIS S.A' (length=13) public 'count' =&gt; string '3' (length=1) public 'ifs_code' =&gt; string '02' (length=2) public 'area_code' =&gt; string '0110' (length=4)
  </code></pre>
  <hr />
  <p>But I dont understand how to take <strong>count(id) as count</strong> in dynamic query.</p>
  <p>I try this:</p>
  <pre><code>$result = db_select('declarations', 'd')
        -&gt;fields('d', array('agent_name', 'ifs_code', 'area_code'))
        -&gt;addExpression('COUNT(id)', 'count') // I THINK I DO SOMETHING WRONG ON THIS LINE
        -&gt;condition('fisccode', $fisccode)
        -&gt;groupBy('agent_name')
        -&gt;range($context['sandbox']['progress'], 10);
  $result-&gt;execute()-&gt;featchAll();
  </code></pre>
  <p>addExpression broke all, after this line phpStorm give me this warning: <strong>Method 'condition' not found in string</strong></p>
  <p>And in drupal log I have this error:  <strong>Call to a member function condition() on string</strong></p>
  <p>Please help me!!!</p>