database measurement_stations
table measurement_station
id : primary key
name : colloquial station name
country : foreign key into table country
table country
id : primary key
name : name of the country
database measurement_values
table measurement_value
id : primary key
station : id of the station the value came from
value : measured value
我需要一份第一个数据库中所有国家的名单,第二个数据库中有这些国家的值。我在InnoDB中使用MySQL,所以支持跨数据库。
选择存在值的国家的ID似乎很容易:
SELECT DISTINCT id FROM measurement_values.measurement_value
第一次这样做需要几分钟时间,但是在随后的调用中速度非常快,即使在数据库服务器重新启动之后也是如此;我认为这是正常的。
我想这本书提到的计数技巧
Problem with Query Data in a Table
和
Mysql Complex Where Clause
我能帮上忙,但我好像做不好。
SELECT country.name FROM measurement_stations WHERE country.id = measurement_station.id
AND (id is in the result of the previous SELECT statement)