SQL为多个条件/条件选择计数

时间:2011-11-01 05:22:45

标签: select count where

这是我正在使用的表和数据:

表名:Customer_Table

Column 1<Product>  Column 2<Region>  Column 3<Customer Status>
EB1                AUSTRALIA         CUSTOMER
PS2                NEW ZEALAND       CUSTOMER
EB1                AUSTRALIA         CUSTOMER
PS2                NEW ZEALAND       DUPLICATE
PS2                NEW ZEALAND       CUSTOMER
PS2                NEW ZEALAND       CUSTOMER
EB1                AUSTRALIA       
EB1                AUSTRALIA         DUPLICATE
EB1                AUSTRALIA         DUPLICATE
EB1                AUSTRALIA         DUPLICATE

我在追求什么?

我正在尝试计算单个值

  
      
  1. 第1列= EB1
  2.   
  3. AND COLUMN 2 =澳大利亚
  4.   
  5. AND列3排除所有重复项但计算空值
  6.   

最终结果应为= 3

1 个答案:

答案 0 :(得分:1)

使用

SELECT COUNT(*) 
FROM Customer_Table WHERE 
Column3 NOT IN ( 'DUPLICATE' ) AND 
Region = 'AUSTRALIA' AND 
Product = 'EB1';