0

So I have a schema that goes something like this

Historical -- Table
--CID
--ID
--LOCATION --STATUS
--TIME

CID doesn't matter for this, but I do want to get the 1 oldest TIME (TimeStamp) for each ID

So what I'm trying to do is something like

SELECT DISTINCT(id) from Historical order by TIME asc limit 1 But where I get each ID, and the oldest time for it.

Thanks

4

2 回答 2

7

这是做你想做的吗?

SELECT id, min(time) FROM Historical GROUP BY id;
于 2013-04-26T15:10:34.283 回答
0
SELECT id, MIN(TIME) FROM Historical GROUP BY id;

这将选择不同的 ID(通过分组)和每个分组 ID 的 MIN TIME。

于 2013-04-26T15:11:45.693 回答