可以啊,group by 本来就属于查询语句里面的一分子
这是我工作中用到的一个查询,给你看看
select count(*) from (
select patientid from (select distinct a.PatientID, a.visitid from Medi_OfficeVisit a
left join Pati_InsuPlan b on a.PatientID=b.PatientID left join Ref_InsuCom c on b.TempInsuComID=c.InsuComID
left join Medi_OV_cpt d on a.visitid=d.visitid
where a.clinicid=1004 and a.VisitDate > '2010-1-1'
and a.VisitDate <'2011-1-1'
and c.InsuComSubmitType ='C' --medicare
and b.InsuOrder =1 --first insurance
and (
d.cptCode like '%99211%' or
d.cptCode like '%99212%' or
d.cptCode like '%99213%' or
d.cptCode like '%99214%' or
d.cptCode like '%99215%' or
d.cptCode like '%99201%' or
d.cptCode like '%99202%' or
d.cptCode like '%99203%' or
d.cptCode like '%99204%' or
d.cptCode like '%99205%' )
group by a.PatientID,a.visitid) t
group by PatientID having COUNT(0)>1
) t2
可以