如何在 SQL 服务器中为所有其他 OR 条件设置 AND 条件?

How to set AND condition is for all to other OR Condition in SQL Server?

我想在 WHERE 子句中使用 ANDOR 设置条件。但问题是 AND 条件未设置为所有其他 OR 条件

例如:

SELECT
    Item,
    Name,
    Brand,
    Date,
    StoreID
FROM
    Item
WHERE
    Date between '01-01-2017' and '30-01-2017' 
    OR Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo'

In my scenario I cannot use IN to select multiple Brand. So I want to set all Date filter to all the brands. How can I achieve it.

谢谢

这将为您提供与这两个子句匹配的所有结果

WHERE
    (Date between '01-01-2017' and '30-01-2017') 
     AND 
    (Brand IN ('Nike','Jhonson','Polo'))

这将为您提供与任何子句匹配的所有内容

WHERE
    (Date between '01-01-2017' and '30-01-2017') 
     OR 
    (Brand IN ('Nike','Jhonson','Polo'))
SELECT
    Item,
    Name,
    Brand,
    Date,
    StoreID
FROM
    Item
WHERE
    Date between '01-01-2017' and '30-01-2017' 
    AND ( Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo')

你的结果可能是对的。

我们这里有两个场景如下

  SELECT
        Item,
        Name,
        Brand,
        Date,
        StoreID
    FROM
        Item
    WHERE
        Date between '01-01-2017' and '30-01-2017' 
        OR (Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo')


SELECT
    Item,
    Name,
    Brand,
    Date,
    StoreID
FROM
    Item
WHERE
    Date between '01-01-2017' and '30-01-2017' 
    AND (Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo')