我有一个查询要从 tableA 中选择一些与 tableB 中的某些行匹配的数据。尽管它的工作原理很慢,但返回几百行大约需要 20 分钟。这是查询,希望您有一些建议可以改进或更改。
我正在使用 SQL Server 2008
DECLARE @MaxDate DATETIME
SELECT @MaxDate = MAX(TimeStamp) -- I know it's not the best column name
FROM tableA
WHERE CodeName IN
(SELECT Tag FROM TableB
WHERE POSITION = 'UP' AND PLACE = 'Shelf')
IF @MaxDate > '2011-08-08'
BEGIN
SELECT @MaxDate = MAX(TimeStamp) -- I know it's not the best column name
FROM tableA
WHERE CodeName IN
(SELECT Tag FROM TableB
WHERE POSITION = 'UP' AND PLACE = 'Shelf')AND TimeStamp >= '2008-12-24' AND TimeStamp < '2010-12-24'
END
ELSE
PRINT 'Date out of range'