Case when ……… then………else ……end
2010-09-14 11:07
106 查看
sql范例:
CASE的多条件应用
select Email,count(Guid)as TotalOrderCount,sum(case when PromotionType=8 then 1 else 0 end)as OriginalCount, sum( SaleTotalPrice )as SumTotalPrice,sum(case when PromotionType=8 then SaleTotalPrice else 0 end)as SumOriginalPrice into #t from #torder group by Email order by Email
CASE的多条件应用
select email,(CASE WHEN createmonth=1 THEN case when promotion=1 then 1 else 0 end ELSE 0 END) as ontad, (case when createmonth=1 then case when promotion=1 then 1 else 0 end else 0 end )as onefeiad, (case when createmonth=2 then case when promotion=1 then 1 else 0 end else 0 end )as twoad, (case when createmonth=2 then case when promotion=1 then 1 else 0 end else 0 end )as twofeiad from #o_one select email,sum(CASE WHEN createmonth=1 and promotion=1 then 1 ELSE 0 END) as ontad sum(case when createmonth=1 and promotion=1 then 1 else 0 end )as onefeiad, sum(case when createmonth=2 and promotion=1 then 1 else 0 end )as twoad, sum(case when createmonth=2 and promotion=1 then 1 else 0 end )as twofeiad from #o_one
相关文章推荐
- sql语句 case when then else end 语句实例
- [ORACLE] case when then else end 应用
- DB2 的 case when then else end 条件分支的处理
- MYSQL 多条件查询(case when then else end)案例
- SQL Case When Then Else End的使用收集
- case when then else end总结
- SQL CASE WHEN ... THEN ... ELSE.. END 实例
- [ORACLE] case when then else end 应用
- SQL中的case when then else end用法
- 学习SQL日记--case a when 1 then x when 2 then y else a end
- SQL中的case when then else end详细用法
- case when then else end
- MySql 中 case when then else end 条件控制语句的用法
- Oracle 查询中判断语句的写法case when then else end
- SQL中的case when then else end用法
- case when then else end 用法--很好
- case 字段 when 值 then 新值 else 值 end 字段
- case when then else end
- mysql操作查询结果case when then else end用法举例
- SQL中的case when then else end用法