我在大约 1:10 秒内返回 250,000 条记录......对于工作来说太长了?
我觉得 SQL Server 应该更快..
SELECT ColOne
FROM TableA WITH (nolock)
WHERE EXISTS (SELECT ColOne
FROM VIEW_1 WITH (nolock)
WHERE LastDate < GETDATE() - 30)
有什么提高速度的方法吗?还是我犯了错误?
*EDIT 澄清有关视图的任何问题 - VIEW_1 有可能拥有多个 ColOne 记录。
查看 SQL:
SELECT MAX(LastSeen) AS LastSeenDate, IDValue
FROM dbo.IDValueTable_LASTSEEN WITH (nolock)
WHERE (LastSeen IS NOT NULL) AND EXISTS (SELECT IDValue
FROM dbo.IDValueTable WITH (nolock)) GROUP BY IDValue
**更新我相信这是有效的查询(我仍然需要确认没有或多或少的记录可以找到)
SELECT DISTINCT IDValue FROM dbo.IDValueTable_LASTSEEN WITH (nolock)
WHERE (LastSeen IS NOT NULL) AND (LastSeen < GETDATE() - 30)
AND IDValue IN (SELECT IDValue FROM dbo.IDValueTable WITH (nolock))
我们需要同时应用 DISTINCT 和你的 IN not EXISTS