title: Find highest count totals via PIVOT?
body: <p>I have a large dataset wherein I need to count "Yes" responses for each question.  My query looks like this:</p>
  
  <pre><code>SELECT 
  SUM(CASE (question1) WHEN 'Y' THEN 1 ELSE 0 END) as question1
  , SUM(CASE (question2) WHEN 'Y' THEN 1 ELSE 0 END) as question2
  , SUM(CASE (question3) WHEN 'Y' THEN 1 ELSE 0 END) as question3
  , SUM(CASE (question4) WHEN 'Y' THEN 1 ELSE 0 END) as question4
  , SUM(CASE (question5) WHEN 'Y' THEN 1 ELSE 0 END) as question5
  ...... ( + dozens more ) ...
  FROM myTable
  </code></pre>
  
  <p>This gives me a table like this: </p>
  
  <pre><code>question1 | question2 | question3 | question4 | question5 | ...
  -------------------------------------------------------------------
  346       | 187       | 240       | 256       | 261       | ...
  </code></pre>
  
  <p>Fine. But I need to find the highest 3 values in this row.  I've researched the PIVOT function in an attempt to transform my table to look like this:</p>
  
  <pre><code>name      | value
  --------------------
  question1 | 346
  question2 | 187 
  question3 | 240
  question4 | 256
  question5 | 261
  </code></pre>
  
  <p>but I frankly don't understand how the FOR ... IN section of the example code works, and moreover, how I'm supposed to list a column "that contains values that will become column headers", as the documentation explains:</p>
  
  <pre><code>PIVOT
  (
      &lt;aggregation function&gt;(&lt;column being aggregated&gt;)
  FOR
  [&lt;column that contains the values that will become column headers&gt;]
      IN ( [first pivoted column], [second pivoted column],
      ... [last pivoted column])
  ) AS &lt;alias for the pivot table&gt;
  </code></pre>
  
  <p>Since I have a table with only 1 row, I don't have a column that will become column headers. Can anyone help me understand how to this works with my 1 row dataset - or better yet, a different way of approaching this?  I feel like I may be missing something simpler.  Again, the end goal is to find the 3 questions with the highest totals.  </p>