【发布时间】:2012-03-02 01:08:24
【问题描述】:
我有一个表格,其中包含我转换的“通话开放日期”列 (actual_log_date),使用
convert(char(10), actual_log_date, 103) 'Call Logged'
例如显示 2012 年 1 月 2 日登录的通话。
还有一个关闭时间列 (close_time),我对其运行相同的转换,
convert(char(10), close_time, 103) 'Call Closed'
显示 2012 年 12 月 2 日结束的通话。
现在,我需要生成一个脚本来获取电话已打开的平均天数。我可以跑
(select datediff(dd, c.actual_log_date, c.close_time)) as 'Days Open'
要创建显示通话已开放 12 天或其他任何时间的列,但现在需要计算所有记录并在结果结束时获得平均总和,这就是我卡住的地方!
我忘了说我不能创建临时表,因为我只有只读权限。
抱歉,我是新来的,所以不确定协议,但如果看到我正在使用的内容更容易回答,这里是脚本;
select
convert(char(10),actual_log_date,103) 'Call Logged',
call_number 'Call #',
short_problem 'Issue Description',
Customer = (select surname + ', ' + first_name from i.ar_user_attributes where ref = user_ref ),
Officer = (select surname + ', ' + first_name from i.su_help_centre where ref = resolve_officer),
Department = (select name from i.su_support_group where ref = resolve_group),
convert(char(10),close_time,103) 'Closed',
(select datediff(hh,c.actual_log_date,c.close_time)) as 'Hours Open',
(select datediff(dd,c.actual_log_date,c.close_time)) as 'Days Open'
from
i.cl_call_logging c
where
c.resolve_time between
convert(datetime,convert(varchar,month(dateadd(m,-1,getdate()))) + '/01/' + convert(varchar,year(dateadd(m,-1,getdate())))) and
convert(datetime,convert(varchar,month(getdate())) + '/01/' + convert(varchar,year(getdate())))
and c.resolve_group in ('48', '60')
再次感谢!
【问题讨论】:
-
欢迎使用 StackOverflow:如果您发布代码、XML 或数据示例,请在文本编辑器中突出显示这些行并单击“代码示例”按钮 (
{ }) 在编辑器工具栏上以很好地格式化和语法突出显示它! -
您如何处理尚未解决的问题?
-
未关闭的调用不会被拉入脚本。
标签: sql sql-server-2008 average