0

我有下表。我想按时间(asc)获得每个源订单的 1 个。来源不固定 - 它可以是任何东西

Time                    |Source
------------------------------------
2012-08-18 05:00:03.000 | A
2012-08-19 06:00:03.000 | B
2012-08-18 06:00:03.000 | B
2012-08-20 06:00:03.000 | C
2012-08-21 06:00:03.000 | A

所以根据上表我会得到下面的结果

Time                    |Source
------------------------------------
2012-08-18 05:00:03.000 | A
2012-08-18 06:00:03.000 | B
2012-08-20 06:00:03.000 | C
4

2 回答 2

2

您想使用MIN()聚合函数和GROUP BY源值。所以我相信这会做你想要的。(参见SQL Fiddle with Demo

select min([time]) minTime, source
from yourTable
group by source
order by minTime
于 2012-08-08T20:36:19.277 回答
1
select id, source, min(time) t 
from table 
group by source, id
order by t
于 2012-08-08T20:36:13.200 回答