[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Access query to add up most frequent calls

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
Alansherwen
Asked:
Alansherwen
1 Solution
 
borkiCommented:
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
 
AlansherwenAuthor Commented:
Thanks for that, fixed it straight away.

Many thanks.

Alan
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now