Solved

Access query to add up most frequent calls

Posted on 2011-02-24
2
334 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Stopping execution of code while print previewing reports access 2010 24 27
Sql query 34 22
add 1 to a field for 100 rows 11 24
Query 14 22
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Viewers will learn how the fundamental information of how to create a table.

744 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

13 Experts available now in Live!

Get 1:1 Help Now