select p.province, data.existUserCount, data.addUserCount, data.cancelUserCount, data.threedayCancelUserCount
, data.addUserCount-data.cancelUserCount realAddUserCount
, to_char(decode(data.existUserCount+data.cancelUserCount,0,0.00,round(data.cancelUserCount*100/(data.existUserCount+data.cancelUserCount),2)),'fm990.00')|| '%' 流失率
, to_char(decode(data.addUserCount,0,0.00,round((data.addUserCount-data.cancelUserCount)*100 /data.addUserCount,2)),'fm990.00')|| '%' 产品留存率
from (select pro.pro_province_name province from m_province pro where pro.pro_is_show = 1) p
left join
(select o.ord_user_province province,
sum(case when o.ord_status = 210 and o.ord_success_time <= to_date('2015-08-05 00:00:00','yyyy-mm-dd hh24:mi:ss') then 1 else 0 end) as existUserCount,
sum(case when o.ord_status = 210 and o.ord_success_time > to_date('2015-08-04 00:00:00','yyyy-mm-dd hh24:mi:ss')
and o.ord_success_time <= to_date('2015-08-05 00:00:00','yyyy-mm-dd hh24:mi:ss')then 1 else 0 end) as addUserCount,
sum(case when o.ord_status = 999 and o.ord_ret_success_time > to_date('2015-08-04 00:00:00','yyyy-mm-dd hh24:mi:ss')
and o.ord_ret_success_time <= to_date('2015-08-05 00:00:00','yyyy-mm-dd hh24:mi:ss')then 1 else 0 end) as cancelUserCount,
sum(case when o.ord_status = 999 and o.ord_ret_success_time < o.ord_success_time + 3 and
o.ord_success_time > to_date('2015-08-04 00:00:00','yyyy-mm-dd hh24:mi:ss')
and o.ord_success_time <= to_date('2015-08-05 00:00:00','yyyy-mm-dd hh24:mi:ss')then 1 else 0 end ) as threedayCancelUserCount
from t_order_info o group by o.ord_user_province) data on data.province = p.province
order by p.province ;
select round(0.0123,2) || '%' from dual;
select to_char(round(0,2),'fm990.00')|| '%' from dual;