oPg Gaming Forum
May 25, 2012, 10:01:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
Make payments with PayPal - it's fast, free and secure!
News: Stay tuned to opggaming.com for new features, modifications, and improvements.
 
   Home   opggaming Help Arcade Search Calendar stats SourceBans Login Register  


hd-gaming
Pages: [1]   Go Down
  Print  
Author Topic: Any DBAs in the house?  (Read 1335 times)
0 Members and 2 Guests are viewing this topic.
mofo
oPg Server Admins
Hero Member
****
Posts: 797


tetris is so unrealistic


« on: April 21, 2007, 10:42:10 PM »

  I have a client who wants to display the average answer speed for all the calls coming in for the day per that queue (there are four queues)
 
  The data, to be displayed correctly, is in two tables. Anway... I know there has to be a COUNT somewhere to count the amount of calls for that queue and then I have to sum the queue times and divide by the sum of calls.
 
  So, I'm really not that good with SQL, I guess I just haven't needed to ever do anything like this before. Anywho - I think I would have to declare some variables and maybe make a stored proceedure
 
  This is as far as I got:

SELECT
    resourceGroupName,
    queueTime,
    startDateTime
  FROM
    ResourceGroup,
    ContactRoutingDetail
  WHERE
    (ResourceGroup.ResourceGroupID = ContactRoutingDetail.rsrcGroupID) AND
    (queueTime > 0) AND
    (startDateTime >= DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 0)) AND
    (startDateTime < DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 1))
  ORDER BY
    resourceGroupName


pleh - I'm probably way off here...  any help would be cool.

thx
Logged

Kjuib
Sr. Member
****
Posts: 498


cube (kjuib) - n. a 3-Dimensional Square


WWW
« Reply #1 on: April 22, 2007, 08:00:33 AM »

The Names and faces have changed to protect the logic...

Code:
SELECT queue.name AS queueName, AVG(queue.endtime - queue.starttime) AS avgTime, COUNT(queue.id) AS callCount, queue.date AS queueDate

FROM resourcegroup
  INNER JOIN contactroutingdetail ON (resourcegroup.resourcegroupid = contactroutingdetail.rsrcgroupid)

WHERE queue.date BETWEEN somestartdate AND someenddate

GROUP BY queue.name, queue.date
ORDER BY queue.date, queue.name

Doing an Inner join while speed up your query.. (But if the tables are under 100,000 records you probably wont notice)
That is the basic layout though, you might have to do some datatype changes.

Personally I hate putting in a timestamp field where the date is going to be queried... I would much rather have 2 fields, one for date and one for time. It makes the SQL a lot simplar.
Logged

pre?venge (pri-venj') - v. - To inflict punishment in return for (injury or insult) before the (injury or insult) happens
mofo
oPg Server Admins
Hero Member
****
Posts: 797


tetris is so unrealistic


« Reply #2 on: April 22, 2007, 11:12:43 AM »

Kjuib - Thanks for the help. The only problem is that there isn't a queue start and end time. The queue time is just a number.

here is what the tables look like:

[ResourceGroup]
resourceGroupID   profileID   resourceGroupName   active
3                         1                Help Desk              True   


[contactRoutingDetail]
sessionID    rsrcGroupID   queueTime   startDateTime
66000057523      4               1      4/21/2007 11:45:02 PM


Thanks again man.

Logged

mofo
oPg Server Admins
Hero Member
****
Posts: 797


tetris is so unrealistic


« Reply #3 on: April 22, 2007, 11:49:22 AM »

Nevermind - figured it out... Thanks!! again for your help.


-mike
Logged

mofo
oPg Server Admins
Hero Member
****
Posts: 797


tetris is so unrealistic


« Reply #4 on: April 22, 2007, 01:32:09 PM »

Deerrrr...

OK... I'm retarded. I explained it wrong... I already had this number. I was looking for the "% calls answered in 20 seconds".

I'm gonna try again.
Logged

mofo
oPg Server Admins
Hero Member
****
Posts: 797


tetris is so unrealistic


« Reply #5 on: April 22, 2007, 02:36:05 PM »

More I try - the more I realize i suck at SQL...

Anybody know why this doesn't work --

(COUNT(queueTime) < '20') / COUNT(sessionID) AS theNumber

I'm getting this --

Microsoft OLE DB Provider for SQL Server (0x80040E14)
Line 1: Incorrect syntax near '<'.
Logged

Kjuib
Sr. Member
****
Posts: 498


cube (kjuib) - n. a 3-Dimensional Square


WWW
« Reply #6 on: April 22, 2007, 02:38:46 PM »

the COUNT(queuetime) is less then '20' ? that wont get you a number that you are then trying to devide by COUNT(sessionID)...
the < should probably go into the where...
Logged

pre?venge (pri-venj') - v. - To inflict punishment in return for (injury or insult) before the (injury or insult) happens
mofo
oPg Server Admins
Hero Member
****
Posts: 797


tetris is so unrealistic


« Reply #7 on: April 23, 2007, 02:16:42 PM »

I finally got it working completely right

--final query

SELECT
  CSQName,
  convOldestContact,
  loggedInAgents,
  availableAgents,
  callsWaiting,
  callsHandled,
  totalCalls,
  callsAbandoned,
  convAvgWaitDuration,
  endDateTime,
  COUNT(sessionID) AS thecalls
FROM
  RtCSQsSummary
  INNER JOIN ResourceGroup ON (RtCSQsSummary.CSQName = ResourceGroup.ResourceGroupName)
  AND (ResourceGroup.resourceGroupName = RtCSQsSummary.CSQName)
  INNER JOIN ContactRoutingDetail ON (ResourceGroup.resourceGroupID = ContactRoutingDetail.rsrcGroupID)
WHERE
  (ResourceGroup.ResourceGroupID = ContactRoutingDetail.rsrcGroupID) AND
  (queueTime < 20) AND
  (ContactRoutingDetail.startDateTime >= DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 0)) AND
  (ContactRoutingDetail.startDateTime < DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 1))
GROUP BY
  CSQName,
  convOldestContact,
  loggedInAgents,
  availableAgents,
  callsWaiting,
  callsHandled,
  totalCalls,
  callsAbandoned,
  convAvgWaitDuration,
  endDateTime


--end

I am taking the count (where queue time < 20) and dividing it by total calls to give me what I need (via. actionscript).

Thanks for your help Kjuib.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC | Sitemap Valid XHTML 1.0! Valid CSS!


Google visited last this page Today at 02:02:26 PM