select a.*,
RID = (select top 1 ID from b where a.mdate> b.ddate order by b.ddate desc),
dt = (select top 1 ddate from b where a.mdate> b.ddate order by b.ddate desc)
from a
这个语句是我自己写的,但是执行效率很一般。怎么提高效率
------解决思路----------------------
select a.*,
b.id RID,
b.ddate
from (SELECT a1.mdate,
MAX(b1.ddate) ddate
FROM a a1
JOIN b b1
ON a1.mdate > b.ddate
) c
JOIN a
ON c.mdate = a.mdate
LEFT JOIN b
ON c.ddate = b.ddate
效率就降了。
Access的自己翻译。