在以下情况下挣扎
我有两个表city和city_distance
表城市结构:- pkCityID CityName 值示例 {(1,a),(2,b),(3,c),(4,d)}
city_distance结构:- fkCityID fkCitiesID CityDistance 值 {(1、2、3.3),(1、3、4.1),(1、4、6.1)} 等等
注意:-fkCityID和fkCitiesID都是pkCityID的外键
我需要什么:-b c d
现在,我想基于CityName查找fkCitiesID的所有CityName。表示我知道城市名称。
我在做什么:-
此处城市ID为1,然后查询:-
SELECT CityName, d.fkCityID, d.fkCitiesID
FROM city_distance as d inner
join cities as c on d.fkCitiesID = c.pkCityID WHERE fkCityID = 1
如何在单个查询中执行此操作?
答案 0 :(得分:1)
您需要从城市加入city_distance,然后返回回到城市:
override func viewDidLoad() {
super.viewDidLoad()
self.webView.addObserver(self, forKeyPath: "isLoading",
options: [.new], context: nil)
let url = URL(string: "https://google.com")!
let request = URLRequest(url:url)
self.webView.load(request)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "isLoading"{
if webView.isLoading{
print("loading")
}
else{
print("done")
}
}
}
这应该返回Select cities_b.CityName
From cities cities_a
Join city_distance cd On cities_a.pkCityID = cd.fkCityID
Join cities cities_b On cd.fkCitiesID = cities_b.pkCityID
Where cities_a.CityName = 'a';
(您说您想在问题中使用b, c, d
,但我认为这是一个错字,因为我看不到任何图案)