表名: - my_test
$_GET
我需要输出如下
compid roundno
1 1
2 1
2 2
答案 0 :(得分:2)
典型的方法是使用row_number()
:
select compid, roundno
from (select t.*,
row_number() over (partition by compid order by roundno desc) as seqnum
from t
) t
where seqnum = 1;
注意:
rank()
。group by
和max()
。如果有其他列,则上述情况有效。答案 1 :(得分:2)
您可以使用group by
汇总函数compid
select compid, max(roundno)
from tbl
group by compid;
列
{{1}}
答案 2 :(得分:2)
使用聚合函数。 - Max()
select compid,max(roundno)
from my_test
group by compid