Try this
create table test ([Key] int, KeyCon int, Adress varchar(30), CallsCount int);
insert into test values(1, 100,'Build9', 15);
insert into test values(2, 100,'Build0', 10);
insert into test values(3, 101,'Build7', 24);
insert into test values(4, 101,'Build4', 17);
insert into test values(5, 102,'Build3', 10);
insert into test values(6, 102,'Build3-2', 10);
select * from
(select KeyCon,max(callscount) maxqty
from test
group by KeyCon
) g
inner join test t on t.keycon=g.keycon and callscount=maxqty
order by g.keycon
I'll add 1 row to your test data, where 2 rows have equal CallsCount. Both lines will be included in the result.
KeyCon |
maxqty |
Key |
KeyCon |
Adress |
CallsCount |
100 |
15 |
1 |
100 |
Build9 |
15 |
101 |
24 |
3 |
101 |
Build7 |
24 |
102 |
10 |
5 |
102 |
Build3 |
10 |
102 |
10 |
6 |
102 |
Build3-2 |
10 |