I have the following sql producing a list of records:
Select Convert(date,Oppo_Opened) as Date, count(distinct o.Oppo_OpportunityId) as Enquiries , Max(data.[3Hour]) as [3Hour], Max(data1.[24Hour]) as [24Hour]
From Opportunity o Inner Join Company On Comp_CompanyId = o.Oppo_PrimaryCompanyId
Left Outer Join
(Select distinct Convert(date,o.Oppo_Opened) as Opened, --Convert(date,op.Oppo_CreatedDate) as Created,
Count(distinct op.Oppo_OpportunityId) as [3Hour]
From OpportunityProgress op Inner Join Opportunity o On o.Oppo_OpportunityId = op.Oppo_OpportunityId
Where o.Oppo_Deleted is Null and o.Oppo_ChannelId=7 and Convert(date,op.Oppo_CreatedDate) > DateAdd(Day, -60, Getdate()) and op.Oppo_Stage In ('IQ','HQ','3Q')
Group By Convert(date,o.Oppo_Opened) --, Convert(date,op.Oppo_CreatedDate)
--Order By Convert(date,o.Oppo_Opened) desc
) data On data.Opened=Convert(date,Oppo_Opened) --and data.Created=Convert(date,Oppo_Opened)
Left Outer Join
(Select distinct Convert(date,o.Oppo_Opened) as Opened, --Convert(date,op.Oppo_CreatedDate) as Created,
Count(distinct op.Oppo_OpportunityId) as [24Hour]
From OpportunityProgress op Inner Join Opportunity o On o.Oppo_OpportunityId = op.Oppo_OpportunityId
Where o.Oppo_Deleted is Null and o.Oppo_ChannelId=7 and Convert(date,op.Oppo_CreatedDate) > DateAdd(Day, -60, Getdate()) and op.Oppo_Stage In ('SDQ','24Q')
Group By Convert(date,o.Oppo_Opened) --, Convert(date,op.Oppo_CreatedDate)
--Order By Convert(date,o.Oppo_Opened) desc
) data1 On data1.Opened=Convert(date,Oppo_Opened) --and data1.Created=Convert(date,Oppo_Opened)
Where Oppo_Deleted Is Null and Convert(date,Oppo_Opened) > DateAdd(Day, -60, Getdate()) and Comp_sector In ('b','p')
Group By Convert(date,Oppo_Opened)--, data.[3Hour], data1.[24Hour]
I need to add 3 more columns that will hold 5 day averages, I have shown what I am trying to achieve below, is this possible ?
Excel 2010
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
1 | 5 Day Average | ||||||
2 | Date | Enquiries | 3Hour | 24Hour | Enquiries | 3Hour | 24Hour |
3 | 03/05/2016 | 18 | 2 | 7 | 18 | 2 | 7 |
4 | 04/05/2016 | 17 | 4 | 7 | 35 | 6 | 14 |
5 | 05/05/2016 | 24 | 6 | 4 | 59 | 12 | 18 |
6 | 06/05/2016 | 18 | 4 | 4 | 77 | 16 | 22 |
7 | 09/05/2016 | 23 | 6 | 5 | 100 | 22 | 27 |
8 | 10/05/2016 | 32 | 5 | 14 | 114 | 25 | 34 |
9 | 11/05/2016 | 21 | 4 | 10 | 118 | 25 | 37 |
10 | 12/05/2016 | 25 | 1 | 11 | 119 | 20 | 44 |
11 | 13/05/2016 | 24 | 0 | 6 | 125 | 16 | 46 |
12 | 16/05/2016 | 18 | 7 | 7 | 120 | 17 | 48 |
13 | 17/05/2016 | 34 | 2 | 20 | 122 | 14 | 54 |
Sheet2