Sql 在count函数中使用where子句

Sql 在count函数中使用where子句,sql,sql-server-2008,Sql,Sql Server 2008,我希望创建一个包含两列的表。1列包含每月支付的金额,而另一列包含当月订购并在当月支付的客户数量 select sum(paid), count(distinct customer where Order_Month = Paid_Month) from DataTable group by Paid_Month 有一种简单的方法吗?使用大小写表达式: select sum(paid), count(distinct case when Order_Month = Paid_Mon

我希望创建一个包含两列的表。1列包含每月支付的金额,而另一列包含当月订购并在当月支付的客户数量

select sum(paid), count(distinct customer where Order_Month = Paid_Month)
from DataTable
group by Paid_Month

有一种简单的方法吗?

使用
大小写
表达式:

select sum(paid),
       count(distinct case when Order_Month = Paid_Month then customer end)
from DataTable
group by Paid_Month;

使用
大小写
表达式:

select sum(paid),
       count(distinct case when Order_Month = Paid_Month then customer end)
from DataTable
group by Paid_Month;