I’m using SQL Server 2008 With this table :

and i have the following query :
SELECT caller, called, SUM(duration) as duration,
dateadd(DAY,0, datediff(day,0, time))as Batch2 ,
CONVERT(VARCHAR(8), time, 4) AS Batch
FROM Calls oc
WHERE caller='somevalue'
GROUP BY called, dateadd(DAY,0, datediff(day,0, time)),
CONVERT(VARCHAR(8), time, 4),
caller
ORDER BY duration DESC,called
Now i want to order the query by the amount of rows in the query that contain the same called value, meaning first results will be the called that appeared in most days.
Now the closest i got was using :
order by (select count(called) from Calls where called=oc.called ),
duration DESC,
called
But this returns all the appearnces of called in general and not grouped by as my initial query distincts values.
And i can’t use OVER() as that will just return the number of rows in general.
This is an example of the output i have for now :
callervalue somecalledvalue 589 2012-11-21 00:00:00.000 21.11.12
callervalue somecalledvalue 551 2012-11-20 00:00:00.000 20.11.12
callervalue somecalledvalue 506 2012-11-22 00:00:00.000 22.11.12
How can i achive this?
The answer was posted by Chris Bednarski as a comment :
Which did the trick.