Count() Keeps Zeroing Out
<p>I'm trying to do a count statement do show how many specific versions each category has. The problem is, whenever a version is over one, the result zeros out. </p>

<p>For example, if there are three of one category with two of them having one version while the other having another version, the count of the version with two instances will show '0' instead of '2'in the results. When the category has just one of each version, it works perfect. It's only when there is more than one instance of a version that it 0s out. </p>

<p>Does anyone know how to fix? I'm assuming it's in my case statements, but I'm not certain. </p>

<p>My code is below. </p>

<pre><code>select Category, Count(Case When Version = 'Offer' then 1 end) as Offers, Count(Case When Version = 'No Offer' then 1 end) as [No Offers] from (
Select *, ROW_NUMBER() over (Partition By Category order by version) as GroupOrder, DENSE_RANK() over (order by category) as GroupNo From Input 
) A
where groupno in 
(
select groupno from (
Select *, ROW_NUMBER() over (Partition By Category order by version) as GroupOrder, DENSE_RANK() over (order by category) as GroupNo From Input 
) A where GroupOrder &gt; 1) and ID not in 
(
select ID from
(
Select *, ROW_NUMBER() over (Partition By Category, Version order by version) as GroupOrder, DENSE_RANK() over (order by category, Version) as GroupNo From Input 
) A
where groupno in 
(
select groupno from 
(
Select *, ROW_NUMBER() over (Partition By Category, Version order by version) as GroupOrder, DENSE_RANK() over (order by category, Version) as GroupNo From Input 
) A where GroupOrder &gt; 1) 
)
group by Category
order by  Category 
</code></pre>