sql server - SQL - Combine another SELECT query with a JOIN -
i found post on stackoverflow, add summary row totals
what i'm trying accomplish that, converted duration field have listed in statement below. i'm trying total durations column day(24 hr period). don't know if it's possible. let me know. thank you!
;with dupes ( select caller_phone, dialed_phone dbo.pbxdata group caller_phone, dialed_phone ) select c.call_time, c.sales_rep, c.call_type, c.flag1, coalesce(nullif(c.flag3, 'null'),'') flag3, isnull(dupes.caller_phone, '') + isnull(dupes.dialed_phone,'') phone, convert(varchar(8), c.duration, 108) duration dupes join dbo.pbxdata c on dupes.caller_phone = c.caller_phone or dupes.dialed_phone = c.dialed_phone (c.sales_rep 'doug%' or c.sales_rep 'nick%' or c.sales_rep 'bob%' or c.sales_rep 'joe%' or c.sales_rep 'john%') , (c.call_time >= dateadd(day, 0, datediff(day, 0, current_timestamp))) , (c.call_time < dateadd(day, 1, datediff(day, 0, current_timestamp))) , duration = (select cast(dateadd(s, sum(datediff(s, '00:00:00', duration)), '00:00:00') time) dbo.pbxdata) order c.call_time;
if want overall total duration in dupes table, can sum duration there.
;with dupes ( select caller_phone, dialed_phone, convert(varchar(8), sum(c.duration), 108) total_time dbo.pbxdata group caller_phone, dialed_phone ) and add , total_time select statement.
if have multiple days in query, need add date field in dupes , add part of join's on clause.
Comments
Post a Comment