如下电话账单:
要求输出流水账单(含通话时长)+总市话+总长话
--通话流水账单
select [CallerNumber]
,[TelNum]
,datediff(second,[StartDateTime],[EndDateTime]) as '通话时间'
from [mydb2].[dbo].[T_CallRecords1]
没问题
--总长话
select '长话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum Like '0%'
没问题
--总市话
select '市话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum not Like '0%'
也没问题
把三项加起来
--通话流水账单
select [CallerNumber]
,[TelNum]
,datediff(second,[StartDateTime],[EndDateTime]) as '通话时间'
from [mydb2].[dbo].[T_CallRecords1]
union all
--总长话
select '长话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum Like '0%'
union all
--总市话
select '市话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum not Like '0%'
问题来了!怎么解决?
|