1
SELECT
    points.location_id,
    route_locations.route_id

FROM
    points
LEFT JOIN route_locations ON route_locations.location_id = points.location_id
WHERE
    points.id = 199 OR points.id = 205

在这个查询之后,我得到了这个结果..

route_id    location_id
12            69
12            75
14            75

现在我需要 location_id 69 和 location_id 75 的共同值。(此处为 route_id 12)我如何通过查询获得它。

4

1 回答 1

2

您可以尝试以下查询 -

    SELECT
        route_locations.route_id
    FROM points
    JOIN route_locations ON route_locations.location_id = points.location_id
    WHERE
        points.id in (199,205) 
    group by route_locations.route_id
    having count(points.location_id)=2
于 2020-01-09T07:32:01.053 回答