Sql 带postgres的重复记录
大家好,我正在与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
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