这可能是我的一个愚蠢的错误,但我不能完全弄清楚我的情况。 我试图通过一组从下面的方式呈现一个子查询拉数据来计算平均:AVG给出一个计数而不是平均值
TotalPDMPs DefaultClinicID
13996 -1
134 23
432 29
123 26
39 27
13 21
40 24
46 30
1 25
现在平均每个“DefaultClinicID”为“TotalPDMPs”计算是一样的上面的数据。 这里是我的计算平均查询:
select DefaultClinicID as ClinicID, AVG(TotalPDMPs)
from
(select count(p.PatientID) as TotalPDMPs, DefaultClinicID from PatientPrescriptionRegistry ppr, Patient p
where p.PatientID = ppr.PatientID
and p.NetworkID = 2
group by DefaultClinicID) p
group by DefaultClinicID
可有人告诉我,我做错了什么吗?
谢谢。
预期结果是什么? – AvielNiego
你的内部'select'将为每个'DefaultClinicID'返回一个记录你如何期待在外部查询中每个'DefaultClinicID'的不同平均值 –