I want to calculate the overall average just after a count step that I have performed using the following code in MySQL that works well:
mysql> SELECT name2, COUNT(name2) FROM refGene GROUP BY name 2;
name2
is a variable name of one database column which contains the name of human genes, which is normal to have repeat values (for this reason it has been performed a count (through the code indicated above) in order to discover the number of repetitions par gene exists in database), but after this I would like to obtain the overall average value for all genes, not for each one.
Example,
name2
COX2
COX2
BCL
BAX
BRO
BCL
Therefore, we have a count of 2 for COX2, 2 for BCL, 1 for BAX and 1 for BRO. All those values sum up to 6 that (having 4 different genes in the examples) gives an overall mean of 6/4=1.5
Thank you for your help.
答案 0 :(得分:2)
If I understand correctly, you want:
SELECT COUNT(name2) / COUNT(DISTINCT name2)
FROM refGene ;
This gives the overall average.