需要解决一个MYSQL选择查询
在这个查询之后,我得到了这个结果需要解决一个MYSQL选择查询,mysql,Mysql,在这个查询之后,我得到了这个结果 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 现在我需要location_id 69和location_id
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
现在我需要location_id 69和location_id 75的公共值。。(此处为路线识别号12)
我如何通过查询得到它。您可以在下面的查询中尝试-
route_id location_id
12 69
12 75
14 75
在表格格式中显示您的预期结果指定MySQL版本。我只需要两个位置共用的路由\u id..@fahmimysql 5.7@akinaThe点数就是一个例子(可能超过2个),或者总是2个?是的,这些值应该是查询结果而不是参数@FahimiLEFT JOIN是不合逻辑的。换上里面的。
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