我有 2 个表:交易 (a) 和价格 (b)。我想从表 b 中检索在交易日期有效的价格。
表 a 包含文章交易的历史记录:Store_type、Date、Article...
表 b 包含文章价格的历史记录:Store_type、日期、文章、价格
目前我有这个:
Select
a.Store_type,
a.Date
a.Article,
(select b.price
from PRICES b
where b.Store_type = a.Store_type
and b.Article = a.Article
and b.Date = (select max(c.date)
from PRICES c
where c.Store_type = a.Store_type
and c.Article = a.Article
and c.date <= a.date)) AS ART_PRICE
from TRANSACTIONS a
它工作得很好,但由于双子查询,它似乎需要很长时间。可以用 LEFT JOIN 做同样的事情吗?