select ghks 科室 , count(*) 挂号人次 ,
sum(case thbz when '1 ' then 1 end) '退号人次 ',
sum(case thbz when '0 ' then 1 end) '实际人次 '
from tb
where convert(varchar(7),ghrq,120) = '2007-09 '
group by ghks
sum(case thbz when '1 ' then 1 end) '退号人次 ',
sum(case thbz when '0 ' then 1 end) '实际人次 '
from tb
where convert(varchar(7),ghrq,120) = '2007-09 '
group by ghks
select ghks 科室 , count(*) 挂号人次 ,
sum(case thbz when '1 ' then 1 else 0 end) '退号人次 ',
sum(case thbz when '0 ' then 1 else 0 end) '实际人次 '
from tb
where convert(varchar(7),ghrq,120) = '2007-09 '
group by ghks