我有表说此表中的VendorReport我表中有三列ID,PrefixId,Download_date数据,如下所示
ID PrefixId Download_date
1 VIS017 28-09-2012
2 VIS028 29-09-2012
3 VIS035 29-09-2012
4 VIS028 30-09-2012
5 VIS028 29-09-2012
6 VIS028 01-10-2012
7 VIS025 30-09-2012
我想要最小日期的唯一PrefixId记录,如下所示
1 VIS017 28-09-2012
2 VIS028 29-09-2012
3 VIS035 29-09-2012
4 VIS025 30-09-2012
所以我已经试过这个查询,但没有得到预期的结果。
select VendorReport.PrefixId,VendorReport.Download_Date from VendorReport
join (select PrefixId, MIN(Download_Date) d_date from VendorReport group by PrefixId) t2 on VendorReport.PrefixId= t2.PrefixId order by VendorReport.Download_Date asc
目前尚不清楚您想要得到什么。希望这会有所帮助:
WITH T AS
(
select
VendorReport.*,
ROW_NUMBER() OVER (PARTITION BY PrefixID
ORDER BY Download_date, ID) as RowNum
from VendorReport
)
SELECT ID,PrefixId, Download_date
FROM T
WHERE RowNum=1
Order by Download_Date DESC
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句