[英]Average of a Count in Select Statement
I can't seem to solve this riddle. 我似乎无法解决这个谜语。 I have the following statement: 我有以下声明:
SELECT schedule_test.ID, LEFT(schedule_test.Course,2) AS 'Type', COUNT(*) AS
'Count'
FROM schedule_test
GROUP BY ID, Type
It echos the following: 它回应了以下内容:
What can I add to the Select statement to add a 4th column with the average of the count for each Type? 我可以在Select语句中添加什么来添加第4列,其中包含每个Type的平均值? In other words, what was the average count of Type "HS" across all employees? 换句话说,所有员工中“HS”类型的平均数是多少? Tried adding AVG(COUNT(*))
but I get an error, Invalid use of group function
. 尝试添加AVG(COUNT(*))
但我收到错误, Invalid use of group function
。
You can try this: 你可以试试这个:
SELECT .......,
AVG(Count) AS average,
AVG(Count WHEN Type = 'HS' THEN Count ELSE NULL END) AS conditionalAverage
FROM schedule_test
GROUP BY ID, Type;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.