日期:2014-05-16 浏览次数:20545 次
select count(1) as 次数 ,Depart_Name_R +DepartDoctor_Name from PeisPatientExamDepart
where (RowCreateTime>'2013-09-01' and RowCreateTime<'2013-09-30')
order by Depart_Name_R
select Depart_Name_R,
COUNT(*) over(partition by Depart_Name_R) '出现次数',
DepartDoctor_Name_R,
COUNT(*) over(partition by DepartDoctor_Name_R) '出现次数'
from PeisPatientExamDepart
where (RowCreateTime>'2013-09-01' and RowCreateTime<'2013-09-30')
order by Depart_Name_R
select a.epart_Name_R,a.c1,b.DepartDoctor_Name_R,b.c2 from(
select Depart_Name_R,count(*) as c1 from PeisPatientExamDepart
where (RowCreateTime>'2013-09-01' and RowCreateTime<'2013-09-30')
group by Depart_Name_R
)a inner join(
select Depart_Name_R,DepartDoctor_Name_R,count(*) as c2 from PeisPatientExamDepart
where (RowCreateTime>'2013-09-01' and RowCreateTime<'2013-09-30')
group by Depart_Name_R,DepartDoctor_Name_R
)b on a.Depart_Name_R=b.Depart_Name_R
create table PeisPatientExamDepart(Depart_Name_R nvarchar(20),DepartDoctor_Name_R nvarchar(20),RowCreateTime datetime)
insert into PeisPatientExamDepart
select '财务室','张三','2013-09-05' union all
select '财务室','张三','2013-09-08' union all
select '财务室','张三','2013-09-09' union all
select '财务室','张三','2013-09-12' union all
select '财务室','李四','2013-09-05' union all
select '财务室','李四','2013-09-11' union all
select '财务室','李四','2013-09-15'
go
select a.Depart_Name_R,a.c1,b.DepartDoctor_Name_R,b.c2 from(
select Depart_Name_R,count(*) as c1 from PeisPatientExamDepart
where (RowCreateTime>'2013-09-01' and RowCreateTime<'2013-09-30')
group by Depart_Name_R
)a inner join(
select Depart_Name_R,DepartDoctor_Name_R,count(*) as c2 from PeisPatientExamDepart
where (RowCreateTime>'2013-09-01' and RowCreateTime<'2013-09-30')
group by Depart_Name_R,DepartDoctor_Name_R
)b on a.Depart_Name_R=b.Depart_Name_R
/*
Depart_Name_R