我有一个查询捕获多条件的总和(见下文),但是,我想做同样的事情,但如果可能的话在case语句。总结在sql server中的多个条件
原始查询:
select
sum(Total Cost)
from Table
where date between '7/20/2016' and '7/21/2016'
and customer = "New Customer"
and sales like 's%'
我试图把在一个case语句。
select
sum(case when total cost is not null then 1 else
case when customer = 'New Customer' then 1 else
case when sales like 's%' then 1 else
end end end
from table
where date between '7/20/2016' and '7/21/2016'
感谢您的帮助
编辑您的问题,并提供样本数据和期望的结果。你的逻辑并不合理。 。 。你似乎想要一个总是返回1的'case'表达式。 –