两个表:
1:CUSTOMER_ALIGNMENT
  customer_id
  customer_alignment_id
  alignment.role2:CUSTOMER
  customer_id如何计算 customer 是 alignment.role="admin" 在所有customer 数量 中的比率?

解决方案 »

  1.   

    select c.c1/d.c2*100 from
    (select count(*) as c1 from CUSTOMER a, CUSTOMER_ALIGNMENT b where a.customer_id =b.customer_id  and b.alignment.role ='admin') c,
    (select count(*) as c2 from CUSTOMER ) d
      

  2.   

    select c.n1/d.n1*100||'%' from 
    (
           select count(*) as n1 from CUSTOMER a, CUSTOMER_ALIGNMENT b where a.customer_id =b.customer_id  and b.alignment.role ='admin'
    ) c, 
    (  select count(*) as n1 from CUSTOMER  ) d
      

  3.   


    --保留小数点后2位,99.99%的格式。
    select round(c.n1/d.n1,4)*100||'%' from 
    (
           select count(*) as n1 from CUSTOMER a, CUSTOMER_ALIGNMENT b 
                  where a.customer_id =b.customer_id  and b.alignment.role ='admin'
    ) c, 
    (  select count(*) as n1 from CUSTOMER  ) d