sql server 2k5中的条件语句

时间:2010-05-11 16:53:40

标签: sql sql-server

如何过滤此查询以不显示“已停止= 1”且数量= 0“的任何项目?我不想排除值为discontinued = 1的所有项目。这仅适用于项目有中断值= 1,数量= 0。

  select sku,producttitle,location,pt_type as type, vendor_name, 
  active,pricestatus,  disc as discontinued,season,yourprice as  
  customerprice,costprice,quantity,stockvalue 

  from getskus

3 个答案:

答案 0 :(得分:2)

WHERE NOT (discontinued = 1 AND quantity = 0)

这恰好代表了您想要表达的内容。您排除(关键字NOT)行满足两者(关键字AND)您所需的条件。

答案 1 :(得分:0)

SELECT sku,
      producttitle,
      location,
      pt_type AS TYPE,
      vendor_name,
      ACTIVE,
      pricestatus,
      disc AS discontinued,
      season,
      yourprice AS customerprice,
      costprice,
      quantity,
      stockvalue
FROM  getskus
WHERE NOT (disc = 1 AND quantity = 0)

你也可以像这样改变方向

SELECT sku,
       producttitle,
       location,
       pt_type AS TYPE,
       vendor_name,
       ACTIVE,
       pricestatus,
       disc AS discontinued,
       season,
       yourprice AS customerprice,
       costprice,
       quantity,
       stockvalue
FROM   getskus
WHERE  disc <> 1
       OR  quantity <> 0

但我更喜欢第一个

答案 2 :(得分:0)

select sku
       ,producttitle
       ,location
       ,pt_type as type
       ,vendor_name
       ,active
       ,pricestatus
       ,disc as discontinued
       ,season
       ,yourprice as customerprice
       ,costprice
       ,quantity
       ,stockvalue  
from getskus 
WHERE NOT (disc = 1 and quantity= 0)