我想按avfamily分组,选择具有非真实生存价值等于true的记录数量,并将其作为perc值返回。
本质上,第3栏除以第2栏乘以100。
select
avclassfamily,
count(distinct(malware_id)) as cc,
sum(case when livingofftheland = 'true' then 1 else 0 end),
(100.0 * (sum(case when livingofftheland = 'true' then 1 else 0 end) / (count(*)) ) ) as perc
from malwarehashesandstrings
group by avclassfamily having count(*) > 5000
order by perc desc;
可能很简单,但是我的大脑在这里空白。
选择按值分组的值等于
avfamily
的记录数量,并将其作为perc值返回。livingofftheland
true
您可以avg()
为此简单地使用:
select
avclassfamily,
count(distinct(malware_id)) as cc,
avg(livingofftheland::int) * 100 as perc
from malwarehashesandstrings
group by avclassfamily
having count(*) > 5000
order by perc desc
livingofftheland::int
将布尔值设置为0
(false)或1
(true)。该值的平均值为您满足组中条件的记录的比率,以0
和之间的十进制数表示1
,然后可以乘以100
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句