title: How to write a Select with subquery in CakePHP
body: <p>I have the following query:</p>
  
  <pre><code>$queryResult = $this-&gt;Hit-&gt;query(
      "select P, count(S) as S
      from 
      (
          select pattern_id as P, srn as S from hits 
          where job_id=".$id." and srn != ''
          group by srn, pattern_id 
          order by pattern_id, srn
      ) as T 
          group by P
          order by P;"
  );
  </code></pre>
  
  <p>So basically I have a <code>select .. from (select .. ) ...</code> statement.
  It's working perfect while I'm using MySQL. But I have to migrate the DB to PostgreSQL so I would like to change this to the Cake-way. So my question is, how can I interpret this type of query (<code>select from select</code>) in <strong>CakePHP</strong>?</p>
  
  <p>Thanks in advance.</p>