Division with Aggregate Functions in SQL Not Behaving as Expected
问题 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. 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: 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