zoukankan      html  css  js  c++  java
  • 计算通话时长

    #工作需要,很不流利的写了几个sql,最后完成了基本的功能,辛苦编辑,做个备份。

    select * from top_sales;
    select SUBSTRING_INDEX(call_duration,':',1) from top_sales; #第一列时间
    select SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1) from top_sales; #第二列时间
    select SUBSTRING_INDEX(call_duration,':',-1) from top_sales; #第三列时间

    #加0转数字
    #select SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales; #第一列时间
    #select SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales; #第二列时间
    #select SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales; #第三列时间

    #每一列时间求和
    #select sum(a) from (select SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d; #第一列时间
    #select sum(b) from (select SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e; #第二列时间
    #select sum(c) from (select SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f; #第三列时间

    #每一列时间转化成秒
    #select sum(a)*3600 from (select SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d; #第一列时间
    #select sum(b)*60 from (select SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e; #第二列时间
    #select sum(c) from (select SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f; #第三列时间

    #添加一个id然后连接起来
    #select id,sum(a)*3600 j from (select id,SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d; #第一列时间
    #select id,sum(b)*60 h from (select id,SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e; #第二列时间
    #select id,sum(c) i from (select id,SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f; #第三列时间

    #连接起来(表一定要起一个别名)

    select * from (
    (select id,sum(a)*3600 j from (select id,SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d)j,
    (select id,sum(b)*60 h from (select id,SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e)k,
    (select id,sum(c) i from (select id,SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f)l
    )
    where j.id=k.id=l.id;
    #计算总的秒数/3600
    select (j+h+i)/3600 from (
    (select id,sum(a)*3600 j from (select id,SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d)j,
    (select id,sum(b)*60 h from (select id,SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e)k,
    (select id,sum(c) i from (select id,SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f)l
    )
    where j.id=k.id=l.id;

    #计算人均时长
    select (j+h+i)/3600/rs 平均时长 from (
    (select id,sum(a)*3600 j from (select id,SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d)j,
    (select id,sum(b)*60 h from (select id,SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e)k,
    (select id,sum(c) i from (select id,SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f)l,
    (select id,count(*)rs from top_sales)m
    )
    where j.id=k.id=l.id=m.id;

    select left(pjsc,5)平均时长,left(n.pjsc,1)小时,concat('0.',SUBSTRING(n.pjsc,3,4))*60 分钟
    from(
    select (j+h+i)/3600/rs pjsc from (
    (select id,sum(a)*3600 j from (select id,SUBSTRING_INDEX(call_duration,':',1)+0 a from top_sales)d)j,
    (select id,sum(b)*60 h from (select id,SUBSTRING_INDEX(SUBSTRING_INDEX(call_duration,':',-2),':',1)+0 b from top_sales)e)k,
    (select id,sum(c) i from (select id,SUBSTRING_INDEX(call_duration,':',-1)+0 c from top_sales)f)l,
    (select id,count(*)rs from top_sales)m
    )
    where j.id=k.id=l.id=m.id
    )n

  • 相关阅读:
    [原创]Linux下压力测试工具Webbench介绍
    [原创] 测试策略是什么?
    [原创]测试报告模板
    [原创]性能测试基础知识
    [原创]性能测试工具介绍
    [原创]LoadRunner性能测试过程
    [内部资料]LoadRunner培训初级教程
    [原创]什么是性能测试?
    [原创]软件测试CheckList文档
    开源博客秋色园QBlog多用户博客系统安装视频教程
  • 原文地址:https://www.cnblogs.com/timingstarts/p/13458747.html
Copyright © 2011-2022 走看看