mysql日期格式字符串_mysql日期格式与字符串格式的转化

直接贴代码吧,例子在代码里,本例经过测试。

select * from

(

select

str_to_date(concat(substr(ctiWorkEventTbl.hourValue, 1, 4), '-',substr(ctiWorkEventTbl.hourValue, 5, 2),'-',substr(ctiWorkEventTbl.hourValue, 7, 2)), '%Y-%m-%d') strdate ,

concat(substr(ctiWorkEventTbl.hourValue, 1, 4), '-',substr(ctiWorkEventTbl.hourValue, 5, 2),'-',substr(ctiWorkEventTbl.hourValue, 7, 2))

,ctiWorkEventTbl.hourValue

,ctiWorkEventTbl.agentCnt

,ctiCallstaTbl.totalCallCnt/ctiWorkEventTbl.agentCnt as perAgtCallCnt /*坐席平均呼叫次数*/

,ctiCallstaTbl.totalCallCnt

,ctiCallstaTbl.totalOkCallCnt

,ctiCallstaTbl.totalOkCallCnt/ctiWorkEventTbl.agentCnt as perAgtOkCallCnt /*平均通话次数*/

,ctiCallstaTbl.totalBadCallCnt

,ctiCallstaTbl.badToAgtCnt

,ctiCallstaTbl.userAbandonCnt

,ctiCallstaTbl.callDuration

,ctiCallstaTbl.perCallDuration

,ctiCallstaTbl.ringCnt

,ctiCallstaTbl.ringDuration

,ctiCallstaTbl.perRingDuration

,ctiWorkEventTbl.refer2OtherCnt

,ctiWorkEventTbl.transfer2OtherCnt

,ctiCallstaTbl.agentDisconnectCnt

,ctiCallstaTbl.userDisconnectCnt

,ctiCallstaTbl.otherGrpCallInCnt

,ctiCallstaTbl.perOtherGrpCallInCnt

,ctiCallstaTbl.otherGrpCallInDuration

,ctiCallstaTbl.maxCallDuration

from

(

select

substr(starttime, 1, 8) as hourValue

, concat(substr(starttime, 1, 4), '-',substr(starttime, 5, 2),'-',substr(starttime, 7, 2)) starttimestr

,sum(if(calltype = 3 && direction = 1, 1, 0)) as totalCallCnt /*总呼叫次数*/

,sum(if(calltype = 3 && direction = 1 && status = 1, 1, 0)) as totalOkCallCnt/*通话次数*/

,sum(if(calltype = 3 && direction = 1, 1, 0)) as totalCallInCnt/*呼入次数*/

,sum(if(calltype = 3 && direction = 1 && status = 2 , 1, 0)) as totalBadCallCnt/*总失败次数*/

,sum(if(calltype = 3 && detail = 0007 , 1, 0)) as badToAgtCnt/*坐席未接起*/

,sum(if(calltype = 3 && (detail = 0008 || detail = 0106 || detail = 0107), 1, 0)) as userAbandonCnt /*用户放弃*/

,sum(if(calltype = 3 && detail = 0009 , 1, 0)) as agentNoAnswerCnt/*坐席无应答*/

,sum(if(calltype = 3 && direction = 1 && status = 1, duration, 0)) as callDuration/*通话时长*/

,sum(if(calltype = 3 && direction = 1 && status = 1, duration, 0))/sum(if(calltype = 3 && direction = 1 && status = 1, 1, 0)) as perCallDuration/*平均通话时长*/

,sum(if(calltype = 3 && (direction = 1 || direction = 2 ) && ringseconds > 0, 1, 0)) as ringCnt/*振铃次数*/

,sum(if(calltype = 3 && (direction = 1 || direction = 2 ) && ringseconds > 0, ringseconds, 0)) as ringDuration/*振铃时长*/

,sum(if(calltype = 3 && (direction = 1 || direction = 2 ) && ringseconds > 0, ringseconds, 0))/sum(if(calltype = 3 && (direction = 1 || direction = 2 ) && ringseconds > 0, 1, 0)) as perRingDuration/*平均振铃时长*/

,sum(if((calltype = 3 && direction = 1 && disconnection = 2) || (calltype = 3 && direction = 2 && disconnection = 1) , 1, 0)) as agentDisconnectCnt/*坐席挂机*/

,sum(if((calltype = 3 && direction = 1 && disconnection = 1) || (calltype = 3 && direction = 2 && disconnection = 2) , 1, 0)) as userDisconnectCnt/*用户挂机*/

,sum(if(calltype = 3 && direction = 1 && substr(taskid, 9, 6) != substr(department, 15, 6), 1, 0)) as otherGrpCallInCnt /*非本组代答*/

,sum(if(calltype = 3 && direction = 1 && substr(taskid, 9, 6) != substr(department, 15, 6), 1, 0)) / sum(if(calltype = 3 && direction = 1, 1, 0)) as perOtherGrpCallInCnt /*非本组代答率*/

,sum(if(calltype = 3 && direction = 1 && substr(taskid, 9, 6) != substr(department, 15, 6), duration, 0)) as otherGrpCallInDuration /*非本组代答时长*/

,max(if(calltype = 3 && direction = 1 && status = 1, duration, 0)) as maxCallDuration/*最长通话时长*/

from cti_callstat

group by substr(starttime, 1, 8)

) ctiCallstaTbl

left join (

select

count(distinct(agentid))as agentCnt

,substr(etime, 1, 8) as hourValue

,sum(if(event = 5, 1, 0)) as refer2OtherCnt/*咨询次数*/

,sum(if(event = 6 || event = 7 , 1, 0)) as transfer2OtherCnt/*转移次数*/

from cti_workevent

group by substr(etime, 1, 8)

) ctiWorkEventTbl on ctiCallstaTbl.hourValue = ctiWorkEventTbl.hourValue

) d

where d.strdate > date_format('2012-05-03','%y-%m-%d')

总结:

字符串转日期:

str_to_date(concat(substr(ctiWorkEventTbl.hourValue, 1, 4), '-',substr(ctiWorkEventTbl.hourValue, 5, 2),'-',substr(ctiWorkEventTbl.hourValue, 7, 2)), '%Y-%m-%d') strdate

简化就是 str_to_date(‘2012-03-06’,'%Y-%m-%d') strdate

日期格式的格式化:

date_format('2012-05-03','%y-%m-%d')

//

DATE_FORMAT(date,format)

根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December)

%W 星期名字(Sunday……Saturday)

%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)

%Y 年, 数字, 4 位

%y 年, 数字, 2 位

%a 缩写的星期名字(Sun……Sat)

%d 月份中的天数, 数字(00……31)

%e 月份中的天数, 数字(0……31)

%m 月, 数字(01……12)

%c 月, 数字(1……12)

%b 缩写的月份名字(Jan……Dec)

%j 一年中的天数(001……366)

%H 小时(00……23)

%k 小时(0……23)

%h 小时(01……12)

%I 小时(01……12)

%l 小时(1……12)

%i 分钟, 数字(00……59)

%r 时间,12 小时(hh:mm:ss [AP]M)

%T 时间,24 小时(hh:mm:ss)

%S 秒(00……59)

%s 秒(00……59)

%p AM或PM

%w 一个星期中的天数(0=Sunday ……6=Saturday )

%U 星期(0……52), 这里星期天是星期的第一天

%u 星期(0……52), 这里星期一是星期的第一天

%% 一个文字“%”。

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-06-11 14:12

浏览 569

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值