【问题标题】:SQL: add a column that shows the total number of invalid agesSQL:添加一列显示无效年龄的总数
【发布时间】:2021-07-27 21:24:59
【问题描述】:

我有一张这样的桌子,

user_id age
First 101
Second 22
Third 85
Fourth 111
Fifth 109

我只需要添加另一列显示 100 岁以上的总人数。类似于以下内容:

user_id age invalid
First 101 3
Second 22 3
Third 85 3
Fourth 111 3
Fifth 109 3

我该怎么做? 谢谢!

【问题讨论】:

    标签: sql database google-bigquery


    【解决方案1】:
    select *, countif(age > 100) over() invalid
    from `project.dataset.table`    
    

    如果应用于您问题中的样本数据 - 输出是

    【讨论】:

      猜你喜欢
      • 2019-05-03
      • 2015-05-22
      • 2016-06-08
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      相关资源
      最近更新 更多