Without knowing unique key it's really hard to do in readable way (no cross apply
, no windowed functions). If you can afford to add id into your table, you can do:
select *
from yourtable
where
id in (
select min(y.id)
from yourtable as y
inner join (
select [TKG], max([CAP]) as [CAP]
from yourtable
group by [TKG]
) as y2 on y2.[TKG] = y.[TKG] and y2.[CAP] = y.[CAP]
group by y.[TKG]
)
Considering myself lucky that I don't work in SQLite often :)