希望您的<代码>currency_rate table 有一个独特的识别栏。
如果是的话,你可以将问询A和B合并为WHERE条款的单一询问。
SELECT
CurrencyRateID, Rate, Markup
FROM
currency_rate
WHERE
uniqueID = (
SELECT uniqueID
FROM currency_rate
WHERE CurrencyID = (SELECT CurrencyID FROM currency WHERE BaseCurr = 1)
ORDER BY DateTime DESC LIMIT 1
)
否则,你可能不得不重复......
SELECT CurrencyRateID, Rate, Markup
FROM currency_rate
WHERE CurrencyID = (SELECT CurrencyID FROM currency WHERE BaseCurr = 1)
AND DateTime = (SELECT MAX(DateTime)
FROM currency_rate
WHERE CurrencyID = (SELECT CurrencyID FROM currency WHERE BaseCurr = 1))
注:尽管守则重复,但MySQL可能注意到重新计算,只是一次处理。
http://www.un.org。
I just noticed that you could simplify the first option to just use the sub-query...
SELECT CurrencyRateID, Rate, Markup
FROM currency_rate
WHERE CurrencyID = (SELECT CurrencyID FROM currency WHERE BaseCurr = 1)
ORDER BY DateTime DESC LIMIT 1