2 개의 하위 쿼리에서 개수를 가져 오는 다음 쿼리를 사용하면 두 개수의 평균을 구해야합니다. 마지막 쿼리에서 C1에 오류가 발생했습니다.Sql 쿼리 합계 평균
Select c0.hour , AVG(c0.frequency)as 'AVG In', AVG(c1.frequency)as 'AVG Out' from
(SELECT [Network]
,cast ([date time]as date)as 'date'
,datepart(hh,[date time])as 'hour'
,[Scan Type]
,count ([scan type])as frequency
FROM [Pallex-DW].[dbo].[Scans]
where Network like 'fr'and [Scan Type] like '3'
group by Network ,datepart(hh,[date time]),cast ([date time]as date),[Scan Type])as c0
Union
(SELECT [Network]
,cast ([date time]as date)as 'date'
,datepart(hh,[date time])as 'hour'
,[Scan Type]
,count ([scan type])as frequency
FROM [Pallex-DW].[dbo].[Scans] as c1
where Network like 'fr'and [Scan Type] like '11'
group by Network ,datepart(hh,[date time]),cast ([date time]as date),[Scan Type])c1
당신은 c0과 c1에 가입하고 싶을 수도 있습니다 –
나는 노동 조합과 관련된 문제를 해결했습니다 ...하지만 지금 AVG In과 AVG out은 완전히 동일합니다! 왜? – Egidio
@Egidio AVG In 및 Avg Out이 동일하면 문제를 해결하지 못했습니다. – Paparazzi