我有一张包含以下数据的表格。
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
获得此优惠的最佳途径是什么
答案 0 :(得分:3)
如果您将compid
分组,那么您可以使用max()
之类的聚合函数来收集您想要的数据
select compid,
max(manualscandate) as manualscandate,
max(staticscandate) as staticscandate,
max(dynscandate) as dynscandate
from your_table
group by compid