一佳一

记录像1+1一样简洁的代码

导航

sql 视图 字段条件统计

Posted on 2019-01-15 20:35  一佳一  阅读(835)  评论(0编辑  收藏  举报
select top(10) FModelCode,FProductTypeName,FBrandName,FOrganizationName,KOrganizationID,count(0) FALLCount,
sum(case when FStatus >1 then 1 else 0 end) SaleCount,
sum(case when FStatus >0 then 1 else 0 end) SendCount
from VProduct 
group by FModelCode,FProductTypeName,FBrandName,FOrganizationName,KOrganizationID
order  BY SaleCount DESC

sum(如果符合条件1否则0) 这样就可以按照条件统计个数了