如何使用jdbc在单个查询中从两个不同的MySQL数据库中检索数据?
SELECT
a.`driver_id`,
a.`state`,
a.`lat`,
a.`long`,
MAX(a.`time_stamp`) AS timestamp,
b.vehicle_type
FROM `rl_driv_location` AS a, `rl_driver_info` AS b
WHERE a.`state` = 1 AND a.`driver_id` = b.`user_id`
AND b.`vehicle_type` = '"+ cartype +"'
GROUP BY driver_id
rl_driv_location
表格的位置数据库。rl_driver_info
表的核心数据库。答案 0 :(得分:1)
只需指定要检索数据的数据库的名称。见下文。
SELECT
a.`driver_id`,
a.`state`,
a.`lat`,
a.`long`,
MAX(a.`time_stamp`) AS timestamp,
b.vehicle_type
FROM location.`rl_driv_location` AS a, core.`rl_driver_info` AS b
WHERE a.`state` = 1 AND a.`driver_id` = b.`user_id`
AND b.`vehicle_type` = '"+ cartype +"'
GROUP BY driver_id