我有下表。我希望按时间(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
答案 0 :(得分:2)
您想要使用MIN()
聚合函数和GROUP BY
源代码值。所以我相信这会做你想要的。 (见SQL Fiddle with Demo)
select min([time]) minTime, source
from yourTable
group by source
order by minTime
答案 1 :(得分:1)
select id, source, min(time) t
from table
group by source, id
order by t