SQL-带子查询的WHERE和OR

SQL-带子查询的WHERE和OR,sql,tsql,Sql,Tsql,我有一个“where”查询,其中我指定了一个“like”列表以及一个子“where”查询。此查询返回时好像忽略了子查询 我试过了,但没有运气 SELECT * FROM [dbo].[listofmachines] Where LastDateTime <= GETDATE() - 28 and ComputerName like 'PC%' OR ComputerName like 'LP%' OR ComputerName like 'LAPTOP%' AND LatestVers

我有一个“where”查询,其中我指定了一个“like”列表以及一个子“where”查询。此查询返回时好像忽略了子查询

我试过了,但没有运气

SELECT * 
FROM [dbo].[listofmachines]
Where LastDateTime <= GETDATE() - 28
and ComputerName like 'PC%' 
OR ComputerName like 'LP%'
OR ComputerName like 'LAPTOP%'
AND LatestVersion < (
 SELECT MAX(LatestVersion) as 'Current Version'
 from [SomeOther].[Table]
 )
选择*
来自[dbo]。[listofmachines]

其中LastDateTime您需要将您的或条件放在括号中-

SELECT * 
FROM [dbo].[listofmachines]
Where LastDateTime <= GETDATE() - 28
and 
( 
  ComputerName like 'PC%' OR ComputerName like 'LP%' OR ComputerName like 'LAPTOP%'
)
AND LatestVersion < 
 (
   SELECT MAX(LatestVersion) from [SomeOther].[Table]
 )
选择*
来自[dbo]。[listofmachines]

其中LastDateTime需要括号。我认为这是一个印刷错误。