如下的SQL语句:SELECT ID, LastModified, (SELECT TOP 1 WorkType FROM [Works] WHERE StartTime >= (Dateadd(hour, 16, (SELECT TOP 1 StartTime FROM [Logs] WHERE Number = T.Number ORDER BY T.[LastModified],ID)) ORDER BY [LastModified] DESC, ID) AS WorkTypeFROM [MyTable] AS TWHERE ID IN ( 5716, 5715, 5714, 5713, 5712, 5711, 5710, 5709, 5708)该语句的执行结果,子查询取得的WorkType字段是有正确的值的,但是,如果删除条件中的部分ID,比如删除5712之后的ID,再执行,本来应该有值的记录,WorkType却为空值了。按说,SQL中的条件只会影响取到的记录数量,不会影响子查询的值呀。这是怎么回事?能否有人给我解惑?多谢了
添加回答
举报
0/150
提交
取消