SELECT 每个公交车站的最短时间

SELECT the min time for each bus stop

我有一个 table,包含列 time_id、bus_id、stop_id 和时间。像这样:

time_id |bus_id | stop_id |时间
1 |19 | 51 | 00:08:00
2 |19 | 51 | 00:09:00
3 |19 | 51 | 00:10:00
4 |19 | 12 | 00:08:30
5 |19 | 12 | 00:09:30
6 |19 | 12 | 00:10:30
7 |23 | 31 | 00:08:00
8 |23 | 31 | 00:09:00
9 |23 | 31 | 00:10:00
10 |23 | 42 | 00:08:30
11 |23 | 42 | 00:09:30
12 |23 | 42 | 00:10:30

我想要每组(bus_id 和 stop_id)具有最小(时间)的行。像这样:

time_id |bus_id | stop_id |时间
1 |19 | 51 | 00:08:00
4 |19 | 12 | 00:08:30
7 |23 | 31 | 00:08:00
10 |23 | 42 | 00:08:30

任何帮助都会很棒。使用 SQLite。

执行此操作的标准 SQL 是:

SELECT bus_id, stop_id, MIN(time) as time
FROM tablename
GROUP BY bus_id, stop_id
ORDER BY bus_id, stop_id

这将 return 时间字段中公交车和停靠站 ID 的每种组合的最小值。我还使用 ORDER BY 子句对结果进行了排序。