title: How to use multiple aggregate functions with multiple/nested tables?
body: <p>I have an issue similare to <a href="http://forums.devx.com/showthread.php?t=166070" rel="nofollow noreferrer" title="multiple agg functions">multiple agg functions</a>, with the difference that I cover more than one table:</p>
  
  <p>I want to aggregate two-fold over a set of tables (see schema at the bottom):</p>
  
  <p><strong>Current wrong result:</strong>
  (The second column actually counts the items of the third column.)</p>
  
  <pre><code>АВТОМАТИЗИРОВАТЬ 2 HD,agt
  АВТОМАТИЗИРОВАТЬ 2 HD,coordin
  АВТОМАТИЗИРОВАТЬ 2 HD,coordin
  АВТОМАТИЗИРОВАТЬ 5 circum,predic,HD,1-compl,--
  АВТОМАТИЗИРОВАТЬ 2 predic,HD
  АВТОМАТИЗИРОВАТЬ 3 predic,circum,HD
  </code></pre>
  
  <p><strong>Desired result:</strong></p>
  
  <pre><code>АВТОМАТИЗИРОВАТЬ 1 HD,agt
  АВТОМАТИЗИРОВАТЬ 2 HD,coordin
  АВТОМАТИЗИРОВАТЬ 1 circum,predic,HD,1-compl,--
  АВТОМАТИЗИРОВАТЬ 1 predic,HD
  АВТОМАТИЗИРОВАТЬ 1 predic,circum,HD
  </code></pre>
  
  <p>The first column is the verb.<br>
  The third column should specify the usage of the verb in the first column.<br>
  The second column should count how many times this specific usage occurs.</p>
  
  <pre><code>select vp.verb, count(), group_concat(label.name) relation 
  from vp, label, vp_terminal, terminal 
  where label.idlabel==terminal.label_id 
  and vp_terminal.vp_id==vp.idvp
  and vp_terminal.terminal_id==terminal.idterminal
  group by vp.verb, vp.idvp 
  order by verb, relation
  </code></pre>
  
  <p><strong>Database Schema:</strong>
  <img src="https://i.stack.imgur.com/qd00l.png" alt="Database Schema">
  One verb (phrase) contains multiple sets of terminals (= words). <br>
  The actual words don't appear in this result, only their grammatical relation to the verb (HD, agt, coordin, predic …). <br>
  A set of relations defines one usage of the verb phrase and is indicated by one row, with the frequency counted (yet wrongly).</p>
  
  <p><strong>Output of the current query (wrong):</strong>
  <img src="https://i.stack.imgur.com/CbV4q.png" alt="Current output of other rows"></p>