Solved

Get Count By Time Slot

Posted on 2011-03-02
3
366 Views
Last Modified: 2012-05-11
Hi
I have the following raw data
Date         Number Of Calls          Average Wait Time(seconds)
1-Feb-10      2                        7.12
2-Feb-10      5                        10.2
3-Feb-10      20                        19.02
4-Feb-10      2                         2.33
5-Feb-10      1                         0.09
6-Feb-10      6                         1.12
7-Feb-10      8                         8.34

and I wish to get this from the raw data

Wait Time Slot      Number of Calls
< 5 seconds                            9
5 - 10 seconds      10
10 - 15 seconds      5
15 - 20 seconds      20

Has anyone any ideas about something clever I can do with SQL and the RANK() function or something to get the data grouped and totaled by the different Wait Time slots?


0
Comment
Question by:Barry Cunney
  • 2
3 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 35018847
If the first set of data is raw data, then the breakdown of how that average was achieved is not there, and I can't see how you can do that.

for example on 3rd feb, you need to know ho long each of those 50 calls lasted
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35018863
try this
select [Number Of Calls], TimeSlot
from
	(select [Number Of Calls],
		   case 
			 when [Average Wait Time] < 5 then
			   '<6'
			 when [Average Wait Time] < 11 then
			   '6-10'  
			 when [Average Wait Time] < 16 then
			   '11-15'  
			 when [Average Wait Time] < 21 then
			   '16-20'
		   end as TimeSlot
	from  table1) A
group by A.[Number Of Calls], A.TimeSlot

Open in new window

0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 35018882
Include sum
select SUM([Number Of Calls]) as [Number Of Calls], TimeSlot
from
	(select [Number Of Calls],
		   case 
			 when [Average Wait Time] < 5 then
			   '<6'
			 when [Average Wait Time] < 11 then
			   '6-10'  
			 when [Average Wait Time] < 16 then
			   '11-15'  
			 when [Average Wait Time] < 21 then
			   '16-20'
		   end as TimeSlot
	from  table1) A
group by A.[Number Of Calls], A.TimeSlot

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Split character from numbers 3 18
sql calculate averages 18 32
BULK INSERT most recent CSV 19 21
Minus first query 1 0
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now