title: SQL Count elements in pairs
body: <p>I have a simple table</p>
  
  <pre><code>CREATE TABLE aaa AS
  (
    ogid integer NOT NULL,
    ocolor character varying(80) NOT NULL,
    vgid integer NOT NULL,
    vcolor character varying(80) NOT NULL,
  )
  </code></pre>
  
  <p>aa contains some values, like in this example</p>
  
  <pre><code>Ogid OColor Vgid VColor
  1   v       1   v
  1   v       5   r
  1   v       8   g
  2   r       5   r
  3   g       7   r
  4   g       5   r
  5   r       7   r
  5   r       9   g
  6   g       6   g
  </code></pre>
  
  <p>I need to count the number of elements in every couple (OColor, VColor) grouping together simmetric couples ( for example the elements of g-r and r-g go together  ).</p>
  
  <p>I need a result similar to:</p>
  
  <pre><code>OColor Vcolor nelement
  b      b      10
  b      g      16
  g      v      2 
  </code></pre>