以下は私のSQLクエリです...私の平均は合計を平均化するのではなく、SUMを表示するだけです。私はなぜそう思うか分からない。誰でも洞察力を提供できますか?SQL平均が期待どおりに機能しない
SELECT
AVG(a.t1) as '8:00-9:00',
AVG(a.t2) as '9:00-10:00',
AVG(a.t3) as '10:00-11:00',
AVG(a.t4) as '11:00-12:00',
AVG(a.t5) as '12:00-1:00',
AVG(a.t6) as '1:00-2:00',
AVG(a.t7) as '2:00-3:00',
AVG(a.t8) as '3:00-4:00',
AVG(a.t9) as '4:00-5:00',
AVG(a.t10) '5:00-6:00',
AVG(a.t11) as '6:00-7:00',
AVG(a.t12) as '7:00-8:00'
from
(select COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('07:00:00' AS time) AND CAST('08:00:00' AS time) then 1 end) as t1,
COUNT(Case when CAST(Request_Datetime AS time)BETWEEN CAST('08:00:00' AS time) AND CAST('09:00:00' AS time) then 1 end) as t2,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('10:00:00' AS time) AND CAST('11:00:00' AS time) then 1 end) as t3,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('11:00:00' AS time) AND CAST('12:00:00' AS time) then 1 end) as t4,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('12:00:00' AS time) AND CAST('13:00:00' AS time) then 1 end) as t5,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('13:00:00' AS time) AND CAST('14:00:00' AS time) then 1 end) as t6,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('14:00:00' AS time) AND CAST('15:00:00' AS time) then 1 end) as t7,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('15:00:00' AS time) AND CAST('16:00:00' AS time) then 1 end) as t8,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('16:00:00' AS time) AND CAST('17:00:00' AS time) then 1 end) as t9,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('17:00:00' AS time) AND CAST('18:00:00' AS time) then 1 end) as t10,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('18:00:00' AS time) AND CAST('19:00:00' AS time) then 1 end) as t11,
COUNT(Case when CAST(Request_Datetime AS time) BETWEEN CAST('19:00:00' AS time) AND CAST('20:00:00' AS time) then 1 end) as t12 ,
COUNT(Interaction_ID) as dayCount
from rt_queue_delta
Where DateName(dw,Request_datetime) in('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday') and
CAST(Request_datetime as Date) >= '05/01/2015' and Department = 1) as a
あなたは 't1'が単一の数字を表すようにクエリを書いています。 't2'、' t3'などのように。 –