当前位置: 代码迷 >> Sql Server >> 统计字段中的数值,同个字段依据其它字段为条件获取不同的值
  详细解决方案

统计字段中的数值,同个字段依据其它字段为条件获取不同的值

热度:99   发布时间:2016-04-27 11:57:39.0
统计字段中的数值,同个字段根据其它字段为条件获取不同的值?
表 sell_manage 
字段 sm_pricecount , sm_date , sm_state
字段 sm_pricecount 根据时间 sm_date 和 状态(1是,0否) sm_state 获取统计值,能否用一条语句表示啊?

------解决方案--------------------
SQL code
--这样吗?select  --sm_date,  sum(case when sm_state=1 then sm_pricecount else 0 end) as sm_pricecount1,  sum(case when sm_state=0 then sm_pricecount else 0 end) as sm_pricecount0from  sell_manage where   sm_date='xxxxxx'
  相关解决方案