Solved

Help with MySQL Query

Posted on 2013-01-11
1
388 Views
Last Modified: 2013-01-24
Hi,

I have a mysql database which collects phone Call Detail Records (CDR). The fields of the MySQL data / Table is somewhat as follows (i've cut down all whats not necessary):

Phone_Number
Channel_Number
Call_Duration

I need to write a query which would give me a output showing the Average Call Duration of each channel, but the average should be calculated only based on the last 10 calls per channel.

My current query looks as follows:

select Channel_Number, count(0) as cnt, avg(Call_Duration) as ACD from CDR_Table group by Channel_Number

Open in new window


But the above query would give the output based on ALL records available in the table. I just need to only get the average for the last 10 calls per channel.

How can this be achieved?

Thanks!
0
Comment
Question by:shaf81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 38767450
you need to first extract to have the 10 last calls per channel, this into a temp table...
for this, you need of course to have a field which indicates the date of the call, which I presume you have in the same table ...

anyhow, please check this article on how to retrieve the N "last" calls per "group = channel"
http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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