今天学习了一种直接用sql语句实现查询最短路径的方法,为我们的系统开发提供了便利。
String sql ="WITH RECURSIVE transfer (start_station, stop_station, stops, path) AS (\n" + " SELECT station_name, next_station, 1, CAST(CONCAT(line_name,station_name , '->', line_name,next_station) AS CHAR(1000))\n" + " FROM bj_subway WHERE station_name = ?\n" + " UNION ALL\n" + " SELECT p.start_station, e.next_station, stops + 1, CONCAT(p.path, '->', e.line_name, e.next_station)\n" + " FROM transfer p\n" + " JOIN bj_subway e\n" + " ON p.stop_station = e.station_name AND (INSTR(p.path, e.next_station) = 0)\n" + ")\n" + "SELECT * FROM transfer WHERE stop_station = ?;\n";
标签:语句,短路线,name,transfer,stop,next,station,SQL,SELECT From: https://www.cnblogs.com/rsy-bxf150/p/17241404.html