日期:2014-05-18 浏览次数:20640 次
select datename(mm,ExamDateTime) as 月份, sum(case when PatientType=0 then 1 else 0 end) as 门诊人数, sum(case when PatientType=0 then fee else 0 end) as 门诊费用, sum(case when PatientType=1 then 1 else 0 end) as 住院人数, sum(case when PatientType=1 then fee else 0 end) as 住院费用 from 表 where 查询条件=..... group by datename(mm,ExamDateTime)
------解决方案--------------------
select convert(varchar(7),ExamDateTime,120) as 月份, sum(case when PatientType=0 then 0 else 0 end) as 门诊人数, sum(case when PatientType=0 then fee else 0 end) as 门诊费用, sum(case when PatientType=0 then 1 else 0 end) as 住院人数, sum(case when PatientType=0 then fee else 0 end) as 住院费用 from reg_info where convert(varchar(7),ExamDateTime,120) between '2007-12' and '2008-06' group by convert(varchar(7),ExamDateTime,120)