0

我有一个数据表如下。

compid  manualscandate  staticscandate  dynscandate
1       1-Aug-12    3-Aug-12    2-Aug-13
1       2-Aug-12    2-Aug-12    3-Aug-12
1       3-Aug-12    1-Aug-12    1-Aug-12
2       1-May-12    3-May-12    2-May-13
2       2-May-12    2-May-12    3-May-12
2       3-May-12    1-May-12    1-May-12

我需要找到每个compid的最新日期..这样..输出表是

compid  manualscandate  staticscandate  dynscandate
1       3-Aug-12    3-Aug-12    3-Aug-13
2       3-May-12    3-May-12    3-May-12

得到这个的最好方法是什么

4

1 回答 1

3

如果你分组,compid那么你可以使用聚合函数max()来收集你想要的数据

select compid, 
       max(manualscandate) as manualscandate, 
       max(staticscandate) as staticscandate, 
       max(dynscandate) as dynscandate
from your_table
group by compid
于 2013-08-23T11:38:02.090 回答