【发布时间】:2014-01-17 13:04:03
【问题描述】:
我在这个表中有表说 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
【问题讨论】:
标签: sql-server group-by sql-order-by unique