sql统计字段区间分布

2021/11/18 19:40:06

本文主要是介绍sql统计字段区间分布,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

sql统计区间分布

 

    Overall_distribution = spark.sql("""
    select count(*) as total_,
    round(count(case when Completion_rate >= 0 and Completion_rate < 0.25 then 1 end )/count(*),2) as a,
    round(count(case when Completion_rate >= 0.25 and Completion_rate < 0.5 then 2 end )/count(*),2) as b,
    round(count(case when Completion_rate >= 0.5 and Completion_rate < 0.75 then 3 end )/count(*),2) as c,
    round(count(case when Completion_rate  >= 0.75 and Completion_rate <= 1 then 4 end )/count(*),2) as d
    from parsed_df2
    """)
    '''
    +------+----+----+----+----+
    |total_|   a|   b|   c|   d|
    +------+----+----+----+----+
    |136173|0.46|0.12|0.07|0.24|
    +------+----+----+----+----+

 结果如上

 



这篇关于sql统计字段区间分布的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程