title: Division with Aggregate Functions in SQL Not Behaving as Expected
body: <p>I'm trying to do some crosstabs in SQL Server 2008 R2. That part is alright, however, if I try to get percentages for each cell, I run into a problem.</p>
  
  <p>Here is a distilled use case: A survey where people give their favorite color and their favorite fruit. I'd like to know how many like a given fruit AND a given color:</p>
  
  <pre class="lang-sql prettyprint-override"><code>with survey as (
      select 'banana' fav_fruit, 'yellow' fav_color
       union select 'banana', 'red'
       union select 'apple', 'yellow'
       union select 'grape', 'red'
       union select 'apple', 'blue'
       union select 'orange', 'purple'
       union select 'pomegranate', 'green'
  )
  select
      s.fav_color, 
      sum(case 
            when s.fav_fruit = 'banana' then 1
            else 0
          end) as banana, 
      sum(case 
             when s.fav_fruit = 'banana' then 1
             else 0
           end) / sum(1)   -- why does division always yield 0? "+", "-", and "*" all behave as expected.
           * 100 as banana_pct,
       sum(1) as total
  from 
      survey s
  group by
      s.fav_color;
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>fav_color   banana banana_pct  total
  ------------------------------------
  blue        0      0            1
  green       0      0            1
  purple      0      0            1
  red         1      0            2
  yellow      1      0            2
  </code></pre>
  
  <p>What I was expecting:</p>
  
  <pre><code>fav_color   banana banana_pct  total
  ------------------------------------
  blue        0      0           1
  green       0      0           1
  purple      0      0           1
  red         1      50          2
  yellow      1      50          2
  </code></pre>
  
  <p>Please help me to get what I was expecting?</p>