我有下表名为MyTable
First Second Third Fourth
1 Ab Cd 2.3
1 Cq Fe 3.4
2 Dr Dh 1.2
3 Bb Qd 9.8
..........ETC.....................
如何选择按First分组且行数最大为Fourth
的行。所以这将是一个导致
First Second Third Fourth
1 Cq Fe 3.4
2 Dr Dh 1.2
3 Bb Qd 9.8
答案 0 :(得分:5)
试试这个:
select *
from MyTable T
join (Select First,max(Fourth) as Fourth
from MyTable
group by First)a
on T.First=a.First
and T.Fourth=a.Fourth
答案 1 :(得分:2)
试试这个解决方案:
select MT.First, MT.Second, MT.Third, MT.Fourth
from MyTable MT
join ( select first, max(Fourth) as Fourth
from MyTable
group by first
) T on T.first = MT.First
and T.Fourth = MT.Fourth
答案 2 :(得分:0)
select
B.*
from (select T.First, max(T.Fourth) as Fourth from Table as T) as A
inner join Table as B on B.First = B.First and B.Fourth = A.Fourth