我正在尝试将世界银行国家收入水平映射到数据集。收入水平每年都在变化,我需要使用交易的国家和日期将适当的收入水平映射到交易。
下表说明了布局和问题:
Example - Table 1 Table 2
----------------- ----------------------------------------
|ISOCountryCode3, PODate | |CountryAlpha3, StartDate, EndDate, IncomeClass|
|CIV, '2009-11-01' | | CIV, 1989-10-02, 1989-09-12, lower |
|ALB, '2007-01-04' | | CIV, 2009-01-01, 2010-01-01, lower |
| CIV, 2010-01-02, 2011-01-01, middle |
系统应返回:
|CIV, '2009-11-01', lower|
|...
这是我到目前为止尝试过的 SQL
SELECT mergestandard.*,incomeclassifications.IncomeClass
FROM `mergestandard`
LEFT OUTER JOIN incomeclassifications
ON mergestandard.ISOCountryCode3 = incomeclassifications.CountryAlpha3
AND mergestandard.PODate<=incomeclassifications.EndDate
AND mergestandard.PODate>=incomeclassifications.StartDate
不幸的是,系统在收入类别字段中不断返回 null。任何帮助将非常感激!