【问题标题】:DB2 SQL column percentage calculationDB2 SQL 列百分比计算
【发布时间】:2015-06-11 19:54:59
【问题描述】:

需要计算列(字符串)中填充行的百分比。

字符串列可以包含零长度字符串(应排除)

如何用一句话重写这条SQL(不带WITH运算符)?

          with A(COUNT)  // needed rows
             as(
                 select count(FAMILY) from T1 
                    where length(FAMILY)>0
               ),
               B(COUNT) // total rows
             as(
                 select count(*) from T1)

         select A.COUNT*100/B.COUNT from A,B

【问题讨论】:

    标签: sql statistics db2


    【解决方案1】:

    您可以使用子选择而不是 WITH;例如:

    select
      ((select count(*) from T1 where length(FAMILY) > 0) * 100) /
      (select count(*) from T1)
    from sysibm.sysdummy1
    

    【讨论】:

      猜你喜欢
      • 2023-02-01
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      • 2021-12-17
      相关资源
      最近更新 更多