Solved

Access query to add up most frequent calls

Posted on 2011-02-24
2
336 Views
Last Modified: 2012-05-11
I have a query to look through a table and bring back the top 30; Telephone number, Destination, Number of Calls, and Total Cost of the calls.  This works fine on one table but another table (same apart from free call records are ommited) it brings back duplicate rows for telephone numbers (different counts).  Also the counts added together do not equal the actual number of calls.

SQL query below:

SELECT TOP 30 CDR_nf.Telno, CDR_nf.Destination, Count(CDR_nf.TelNo) AS CountOfTelNo, Sum(CDR_nf.cost) AS SumofCost
FROM TelNumbers INNER JOIN CDR_nf ON TelNumbers.Number = CDR_nf.CalledFrom
GROUP BY CDR_nf.Telno, CDR_nf.Destination, CDR_nf.cost
ORDER BY Count(CDR_nf.TelNo) DESC;

I cannot see what I have done wrong here and any hel would be appreciated.

Attached is outut of the SQL (I have blocked out the first part of the telephone numbers and highlighted some duplicates. Screenshot of SQL output
0
Comment
Question by:Alansherwen
2 Comments
 
LVL 9

Accepted Solution

by:
borki earned 250 total points
ID: 34968621
Why are you using

CDR_nf.cost

in the GROUP BY clause? You wo't need it there, as you are using an aggregate on this column.
0
 

Author Closing Comment

by:Alansherwen
ID: 34968625
Thanks for that, fixed it straight away.

Many thanks.

Alan
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

929 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

10 Experts available now in Live!

Get 1:1 Help Now