S Ringne - 1 month ago 12

MySQL Question

i have a table:

`+-----------------+-----------+`

| CategoryCount | frequency |

+-----------------+-----------+

| 0 | 123 |

| 12 | 234 |

| 15 | 456 |

| 0 | 678 |

| 25 | 890 |

| 0 | 145 |

+-----------------+-----------+

it has 300 rows

I want to find total no. of count,where the frequency is less than 75%

i am writing this query:

`select sum(CategoryCount)`

from Session_category_analysis

where frequency/sum(frequency) < 0.75;

but i am getting error as

ERROR 1111 (HY000):Invalid use of group function

i also tried using this query:

`select CategoryCount , frequency`

from Session_category_analysis

where frequency/sum(frequency) < 0.75

group by CategoryCount ;

ERROR 1111 (HY000): Invalid use of group function

also this query, but failed

`select CategoryCount from Session_category_analysis`

where(select frequency/sum(frequency)

from Session_category_analysis

where frequency/sum(frequency) < 0.75

);

ERROR 1111 (HY000): Invalid use of group function

Answer

```
select sum(CategoryCount)
from Session_category_analysis
where (frequency * 100 / (select sum(frequency) from Session_category_analysis)) < 75
```