<p>I have a table with the following columns:</p>

<pre>

A   B   C
---------
1   10  X
1   11  X
2   15  X
3   20  Y
4   15  Y
4   20  Y

</pre>

<p>I want to group the data based on the B and C columns and count the distinct values of the A column. But if there are two ore more rows where the value on the A column is the same I want to get the maximum value from the B column.</p>

<p>If I do a simple group by the result would be:</p>

<pre>

B   C    Count
--------------
10  X    1
11  X    1
15  X    1
20  Y    2
15  Y    1

</pre>

<p>What I want is this result:</p>

<pre>

B   C    Count
--------------
11  X    1
15  X    1
20  Y    2

</pre>

<p>Is there any query that can return this result. Server is SQL Server 2005.</p>

Check this out. This should work in Oracle, although I haven't tested it;
```
```
select count(a), BB, CC from
(
select a, max(B) BB, Max(C) CC
from yourtable
group by a
)
group by BB,CC
```
```