2015-04-07 351 views
0

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

String列,可以包含零个长度字符串(应被排除在外)

如何重新写这个SQL一句话(不带操作员)?

  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 

回答

1

您可以使用子选择代替WITH;例如:

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

谢谢!有用) – gmlvsv