选择mysql返回的所有值的平均值

时间:2013-01-10 22:16:23

标签: mysql sql

如何使用SQL查找此查询的平均值:

SELECT  count(col1) as count FROM table1 GROUP BY col1 HAVING count > 1

我正在尝试查找每col1

的平均行数

到目前为止,我设法找到每col1行的总行数,现在我只需要平均值

2 个答案:

答案 0 :(得分:2)

select avg( c ) 
from ( SELECT  count(col1) as c FROM table1 GROUP BY col1 HAVING count > 1 )

答案 1 :(得分:0)

对于表格,您需要别名并将count更改为count(*)

查询:

SELECT avg(t1.c) AS avgcol1
FROM
  (SELECT count(col1) AS c
   FROM table1
   GROUP BY col1 HAVING COUNT(*) > 1) t1