sql范例: 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