• sql函数应用例子


    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;

  • 相关阅读:
    五分钟搭建起一个包含CRUD功能的JqGrid表格
    TDD学习笔记【六】一Unit Test
    CQRS
    开源一个vue2的tree组件
    权限管理[Linux]
    文件管理[Linux]
    查看文本[Linux]
    常用命令[Linux]
    文件管理[Linux]
    状态机工作流
  • 原文地址:https://www.cnblogs.com/wuer888/p/7479125.html
Copyright © 2020-2023  润新知