使用pandas选择使用除法运算符mysql的stament

时间:2016-11-07 14:06:54

标签: mysql sql

我有一张桌子:

+-----------------+-----------+
|  CategoryCount  | frequency |
+-----------------+-----------+
| 0               | 123       |
| 12              | 234       |
| 15              | 456       |
| 0               | 678       |
| 25              | 890       |
| 0               | 145       |
+-----------------+-----------+

它有300行

我想找到完全没有。计数,频率低于75% 我正在写这个查询:

select sum(CategoryCount) 
from Session_category_analysis 
where frequency/sum(frequency) < 0.75;

但我收到错误

  

ERROR 1111(HY000):无效使用群组功能

我也尝试过使用这个查询:

select CategoryCount , frequency 
from Session_category_analysis 
where frequency/sum(frequency) < 0.75 
group by  CategoryCount ;
  

ERROR 1111(HY000):无效使用群组功能

也是这个查询,但失败了

 select CategoryCount from  Session_category_analysis 
 where(select frequency/sum(frequency) 
   from Session_category_analysis 
   where frequency/sum(frequency)  < 0.75
);
  

ERROR 1111(HY000):无效使用群组功能

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

您可以使用having子句代替其他地方:

select sum(CategoryCount) as 's'
from Session_category_analysis
having s/sum(frequency) < 0.75;