I have a query to get the total duration of phone usage for various users...

But I need to be able to work out distinct averages for their usage.. the problem being certain users share phones and I can only grab phone info, so the call duration is repeated and this would skew the data..

So I need an average and a distinct (on the pin.Number field)... it would also be useful to do a Median if that is possible..??

This is the current query...

```
SELECT TOP 40 SUM(Duration) AS TotalDuration, c.Caller, oin.Name, oin.Email, pin.Number, oin.PRN 
FROM Calls as c 
INNER JOIN Phones as pin On c.caller = pin.id 
INNER JOIN officers as oin On pin.id = oin.fk_phones 
WHERE Duration <> 0 AND Placed BETWEEN '01/07/2011 00:00:00' AND '20/08/2011 23:59:59' 
GROUP BY c.Caller, oin.Name, pin.Number, oin.Email, oin.PRN 
ORDER BY TotalDuration DESC  

```

Many thanks for any pointers

Here's an example of the current data I am after (but I have added the averages below which is what I am after), as you can see some users share the same phone but the number of seconds is shared between them so don't want that to influence the average (I don't want 11113 seconds repeated), so there needs to be a distinct on each phone number..

![enter image description here](https://i.stack.imgur.com/h55EK.jpg)