Hi Experts,
I have below table structure
DECLARE @table Customer (Date DATE, CustomerID VARCHAR(5))
INSERT INTO @Customer (Date, CustomerID) VALUES
('2/6/2015','ADXPA'),
('2/6/2015','AKXLV'),
('2/7/2015','CPDYA'),
('2/7/2015','ZXDQW'),
('2/8/2015','LK1MP'),
etc, till 3836 Records for '2/8/2015' and 4869 Records for '2/8/2015' etc...
Now, I want to take the records which are meeting the standard deviation value of count of CustomerIDs in the group.
I hope below will give you more idea...
Date | Count of Customers | Avg. Count | STD DEV |
2/6/2015 | 2 | 3944.07 | 1849.61 |
2/7/2015 | 2 | 3944.07 | 1849.61 |
2/8/2015 | 3836 | 3944.07 | 1849.61 |
2/9/2015 | 4869 | 3944.07 | 1849.61 |
2/10/2015 | 4953 | 3944.07 | 1849.61 |
2/11/2015 | 4913 | 3944.07 | 1849.61 |
2/12/2015 | 5164 | 3944.07 | 1849.61 |
2/13/2015 | 4292 | 3944.07 | 1849.61 |
2/14/2015 | 3463 | 3944.07 | 1849.61 |
2/15/2015 | 5909 | 3944.07 | 1849.61 |
2/16/2015 | 4825 | 3944.07 | 1849.61 |
2/17/2015 | 4490 | 3944.07 | 1849.61 |
2/18/2015 | 4555 | 3944.07 | 1849.61 |
Here I want to filter out +/- STDDEV of Average - So I need to filter out rows with dates 2/6/2015, 2/7/2015 and 2/16/2015 since these values not in the range of +/- STDDEV of Average.
Here CustomerID is Varchar type, So we need to convert them to Count first partitioning the Date Column and take the average and STDDEV of all without any partition...Correct me if I'm wrong...
Pls. help me with a query as I'm struggling it with for some time.... I appreciate your help.
Pls. let me know if you need more details...
Thanks,
dhamu13