title: How to group complicated condition in sql
body: <p>I'd like to group by <code>region</code> where there are <code>customers</code>who has <code>type=a</code></p>
  <pre><code>region customer type score
  A       a        a     1
  A       b        b     2
  A       c        a     3 
  B       d        c     4 
  B       e        d     5 
  C       f        a     6 
  C       g        c     7
  </code></pre>
  <p>Therefore after first step</p>
  <pre><code>region customer type score
  A       a        a     1
  A       b        b     2
  A       c        a     3 
  C       f        a     6 
  C       g        c     7
  </code></pre>
  <p>And then I groupby in <code>region</code></p>
  <pre><code>region  sum(score)
  A         6
  C        13
  </code></pre>
  <p>also I'd like to extract customer whose <code>type=a</code></p>
  <pre><code>region customer type
  A         a      a
  A         c      a 
  C         f      a
  </code></pre>
  <p>Then I'd like to merge above.</p>
  <p>My desired result is like following</p>
  <pre><code>customer sum_in_region
  a           6
  c           6
  f          13 
  </code></pre>
  <p>Are there any way to achieve this?</p>
  <p>My work is till the second step..
  How can I proceed further?</p>
  <pre><code>SELECT t1.region,t1.customer, t1.type, t1.score
    FROM yourTable t1
   WHERE EXISTS (SELECT 1
                   FROM yourTable t2
                  WHERE t2.region = t1.region
                    AND t2.type = 'a');
  </code></pre>
  <p>Thanks</p>