我不知道我是否清楚自己,但希望你们能提前帮助我,而不是提前帮助我。解决方案 SELECT r1.PathId, Go_Back = CASE WHEN GoDistance IS NULL THEN ' 返回' ELSE ' Go' END , CityFrom = r1.City, CityTo = r1.City,距离= ISNULL(GoDistance,BackDistance) FROM dbo.Routes r1 INNER JOIN dbo.Routes r2 ON r1.PathID = r2.PathID AND r1.City<> r2.City Hello,I have a database with many tables, especially two tables one store paths and the other one store cities of a path :Table Paths [ PathID, Name ]Table Routes [ ID, PathID(Forein Key), City, GoTime, BackTime, GoDistance, BackDistance]Table Paths :PathID.......Name1...................NewYork Casablanca Alpha 17...................Paris Tokyo 6007 10:00Table Routes :ID..........PathID..........City....................GoTime..........BackTime..........GoDistance..........BackDistance1............1....................NewYork...........08:00.................23:46...............5810....................NULL2............1....................Casablanca......15:43..................16:03...............NULL....................58003............2....................Paris...................10:20..................14:01...............3215....................NULL4............2....................Cairo..................14:50..................09:31...............2425....................32153............2....................Dubai.................18:21..................06:00...............NULL....................2425I want a Query that gives me all the possible combinations inside the same Path, something like :PathID..........CityFrom..........CityTo..........DistanceI don't know if I made myself clear or not but hope you guys could help me, thanx in advance. 解决方案 SELECT r1.PathId, Go_Back = CASE WHEN GoDistance IS NULL THEN 'Back' ELSE 'Go' END, CityFrom = r1.City, CityTo = r1.City, Distance = ISNULL(GoDistance, BackDistance)FROM dbo.Routes r1 INNER JOIN dbo.Routes r2 ON r1.PathID = r2.PathID AND r1.City <> r2.City 这篇关于SQL查询:如何计算两个城市之间的距离(基于预定义的表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-06 05:42