犀利兵

 

一个使用统计语句select sum(case when ... then ... end) ...(转)

一个统计需求,需要统计产品表中下线产品数量、上线产品数量、热销产品数量、折扣产品数量。要求用一个SQL语句实现! 想到用sum(case when ...then ... end), 如下所示: Select Sum(case when IsOnline = 1 then 1 else 0 end) as OnlineProducts, Sum(case when IsOnline = 0 then 1 else 0 end) as OfflineProducts, Sum(case when IsHot = 1 then 1 else 0 end) as HotProducts, Sum(case when IsDiscount = 1 then 1 else 0 end) as DiscountProducts From Tbl_Product 还有更好的办法吗?.....

posted on 2011-12-30 15:11  犀利兵  阅读(840)  评论(0编辑  收藏  举报

导航