第一个查询应该对记录进行计数-第二个查询需要对计数的记录取平均值。我不知道如何正确使用子查询。这就是我所拥有的;显然,“ birds”列不存在,因为它是在子查询中创建的,因此我的外部查询不起作用:
F4= ISNOT indirect('Autofill'!A2:A343)
答案 0 :(得分:0)
我只能猜测,因为您的问题可能与更详细的描述有关,但也许您想执行以下操作:
SELECT
avg(birds)
FROM (Select
Count(o.ObservationID) as birds
,o.CountID
,mp.MonitoringPointID
FROM [FocalAreas].[dbo].[Observation] as o, FocalAreas.dbo.Count as c, FocalAreas.dbo.MonitoringPoint as mp
where o.CountID = c.CountID
and c.MonitoringPointID = mp.MonitoringPointID
and StateID = 'NE'
and AOUSpeciesID = 1
and Route = 'Focal'
and datepart(year, CountDate) = 2014
group by o.CountID, mp.MonitoringPointID) as subq