【问题标题】:Finding percentage of users with certain conditions查找具有特定条件的用户百分比
【发布时间】:2022-11-12 08:35:20
【问题描述】:

使用 MySQL,我需要从具有以下结构的表中找到 >= 30 AverageActiveMinutes 的用户百分比和 <30 AverageActiveMinutes 的用户百分比:

Id AverageActiveMinutes
1503960366 37.92
1644430081 2.50
1844505072 0.00
3977333714 19.82
5553957443 97.88
7086361926 47.46
8792009665 1.67

我正在寻找具有两列和一行的输出,看起来像这样:

PercentOver30 PercentUnder30
42.9 57.1

【问题讨论】:

    标签: mysql percentage calculation


    【解决方案1】:

    您可以使用聚合:

    select 
        avg(AverageActiveMinutes > 30) PercentOver30,
        avg(AverageActiveMinutes > 50) PercentOver50
    from mytable
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-07
      • 2021-08-06
      • 2017-11-02
      • 2018-02-02
      相关资源
      最近更新 更多