sql 子查询里面可以写group by 吗?(要正确答案)
2个回答
展开全部
可以啊,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
这是我工作中用到的一个查询,给你看看
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
2011-06-16
展开全部
可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |