两个表:
1:CUSTOMER_ALIGNMENT
customer_id
customer_alignment_id
alignment.role2:CUSTOMER
customer_id如何计算 customer 是 alignment.role="admin" 在所有customer 数量 中的比率?
1:CUSTOMER_ALIGNMENT
customer_id
customer_alignment_id
alignment.role2:CUSTOMER
customer_id如何计算 customer 是 alignment.role="admin" 在所有customer 数量 中的比率?
(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
(
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
--保留小数点后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