DB2 SQL 列百分比计算

DB2 SQL column percentage calculation

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

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

如何用一句话重写这个 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

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

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