MYSQL calculating an average on a count

后端 未结 2 827
南笙
南笙 2021-01-28 14:16

I have a simple query that I want an average on. This is what it looks like now, and I want to know the average of my count per Opname_OpnameID.

SELECT Opname_O         


        
相关标签:
2条回答
  • 2021-01-28 14:44

    If you want the average count, presumably over the entire table, then just do exactly that:

    SELECT AVG(cnt) AS total_avg
    FROM ( 
        SELECT COUNT(*) AS cnt FROM behandeling GROUP BY Opname_OpnameID
    ) t;
    
    0 讨论(0)
  • 2021-01-28 14:46

    You can use count(distinct) and not use a subquery:

    SELECT count(*) / count(distinct Opname_OpnameID)
    FROM behandeling
    
    0 讨论(0)
提交回复
热议问题