Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 带postgres的重复记录_Sql_Perl_Postgresql - Fatal编程技术网

Sql 带postgres的重复记录

Sql 带postgres的重复记录,sql,perl,postgresql,Sql,Perl,Postgresql,大家好,我正在与postgres合作以获得结果对,但我得到了重复的记录。 我得到的信息是: stop_name|departure_time ------------------------ AAA | 16489646 BBB | 16465464 AAA | 46546665 AAA | 18421654 BBB | 16849685 AAA | 56496865 我预计会出现以下情况: stop_name|departure_t

大家好,我正在与postgres合作以获得结果对,但我得到了重复的记录。 我得到的信息是:

stop_name|departure_time
------------------------
AAA      | 16489646
BBB      | 16465464
AAA      | 46546665
AAA      | 18421654
BBB      | 16849685
AAA      | 56496865
我预计会出现以下情况:

stop_name|departure_time
------------------------
AAA      | 16489646
BBB      | 16465464

因为有点复杂,我做了一个小提琴,你可以看到一个模式样本和Im使用的查询。有人能帮我达到预期的效果吗?谢谢。

我想您只需要使用
MIN
聚合:

SELECT s.stop_name, min(st.departure_time) departure_time
  FROM stops s
    INNER JOIN stop_times st
      ON s.stop_id = st.stop_id
    INNER JOIN (
      SELECT DISTINCT t.trip_id, t.route_id
        FROM trips t, northbound nb
        WHERE t.trip_id LIKE CONCAT(nb.train_id,'%')
        AND t.route_id = '2'
    ) TR
      ON TR.trip_id = st.trip_id
WHERE st.departure_time > 1373948273
GROUP BY s.stop_name 

你想做什么?这项工作与GTFS(运输)有关,我想在给定的特定时间获得可能的航班。在工作中经过一些讨论后,给出的答案将有效。谢谢!有时候,你被复杂的事物所包围,忘记了简单的事情。这里就是这样:(@LouieV——不用担心,很高兴这有帮助!