【发布时间】:2016-01-18 23:14:10
【问题描述】:
我有一个使用子查询的查询,我想重写为一个连接,以获得更好的性能。 (毫秒访问)
那么我该如何重写这样的查询以使用连接:
SELECT t.StudentID, t.subject, t.testid, t.TestScore, t.ID
FROM MyTable AS t
WHERE (((t.[TestID]) In (SELECT TOP 2 testid
FROM MyTable
WHERE StudentID = t.StudentID
AND subject = t.subject
ORDER BY TestScore asc, testid)))
ORDER BY t.StudentID, t.TestScore, t.testID;
就像 Gordon Linoff 所说,如果这不能轻易地改写为连接语法,那么“not in”又如何呢? 这也很难重写为连接语法吗? 另外,仅供参考,我使用 MS-access。
选择 t.StudentID、t.subject、t.testid、t.TestScore、t.ID 从 MyTable 作为 t WHERE t.TestID 不在(SELECT TOP 2 testid 从我的表 WHERE StudentID = t.StudentID AND 主题 = t.subject ORDER BY TestScore asc, testid))) 按 t.StudentID、t.TestScore、t.testID 排序;【问题讨论】:
标签: sql ms-access join rewrite