title: SQL - CASE WHEN count different values
body: <p>I need to show how many different values every 'id' has.</p>
  
  <p>It should look like this:</p>
  
  <pre><code>id    |  component_a | component_b | component_c
  --------------------------------------------------
  KLS11 |     none     |      one    |     none       
  KLS12 |     one      |      one    |     none         
  KLS13 |     several  |      one    |     none        
  KLS14 |     one      |      one    |     one            
  KLS15 |     one      |    several  |     several           
  </code></pre>
  
  <p>I have the following table (table_a):</p>
  
  <pre><code>id    |  component_a | component_b | component_c
  --------------------------------------------------
  KLS11 |              |      a      |            
  KLS12 |       a      |      a      |              
  KLS13 |       a      |      a      |             
  KLS13 |       b      |      a      |               
  KLS14 |       a      |      a      |      a        
  KLS15 |       a      |      a      |      a                
  KLS15 |       a      |      b      |      b
  </code></pre>
  
  <p>Here an example/explanation:   </p>
  
  <ul>
  <li>KLS13 has different values in component_a ( a,b ) - so it should display '<strong>several</strong>'       </li>
  <li>KLS13 has the same values in component_b ( a,a ) - so it should display
  '<strong>one</strong>'  </li>
  <li>KLS13 has no value in component_c - so it should display '<strong>none</strong>'</li>
  </ul>
  
  <p>Here's my SQL-code:    </p>
  
  <p>I already did it for component_a but it doesnt work. What am i doing wrong?</p>
  
  <pre><code>SELECT 
  CASE WHEN component_a is NULL THEN 'none'
       WHEN (SELECT count(DISTINCT component_a) 
               FROM table_a
                WHERE id=(SELECT id 
                            FROM table_a GROUP BY id HAVING count(*)&gt;1)&gt;1 THEN 'several'
       WHEN (SELECT count(DISTINCT component_a) 
               FROM table_a
                WHERE id=(SELECT id 
                            FROM table_a GROUP BY id HAVING count(*)&gt;1)=1 THEN 'one'
  END as componentA
  FROM table_a
  </code></pre>
  
  <p>i am a beginner at SQL so i would appreciate any help.</p>
  
  <p>Have a nice day</p>