title: T-SQL Group by with a where clause
body: <pre><code> Masterid    CC  CLA DES NLCLA   NLDES
   -------------------------------------
   53006141    CN  0   0   1       1
   53006141    US  1   1   1       1
   53006141    UK  1   1   0       0
   53006142    US  1   1   0       0
   53006142    UK  1   1   0       0
   53006143    CN  0   0   1       1
   53006143    US  1   1   0       0
   53006143    UK  1   1   0       0
  </code></pre>
  
  <p>From the above data I need to produce </p>
  
  <ul>
  <li>a list of <code>MasterIds</code> where there is <code>CC = US</code> or <code>CC = CN</code> and <code>NLCLA = 1</code> and <code>NLDES = 1</code> </li>
  </ul>
  
  <p>The output should be</p>
  
  <pre><code>53006141
  53006143
  </code></pre>
  
  <p>There has to be both CN and US under a MasterID.</p>
  
  <p>Can someone help me to do this in SQL please?</p>