?
Solved

Count Data then Sum Rows

Posted on 2009-02-12
7
Medium Priority
?
1,599 Views
Last Modified: 2012-06-27
Hello:

I have this SQL Statement: SELECT Count(FinalData) AS Total FROM Data
It displays the results in a row like this:

34
78
44
90
35

The results are correct. How can I sum the results after I count them?
 
0
Comment
Question by:RecipeDan
7 Comments
 
LVL 25

Expert Comment

by:reb73
ID: 23625276
Add the following at the end of the SELECT statement -

COMPUTE SUM(COUNT(FINALDATA))
0
 
LVL 12

Expert Comment

by:Nathan Riley
ID: 23625381

SELECT sum(Count(FinalData)) AS Total FROM Data

Open in new window

0
 
LVL 25

Expert Comment

by:reb73
ID: 23625515
Gallitin -> Your query will yield the following error message -

Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

The count(finaldata) in the original query is resulting in multiple rows because there is a grouped field which has not been indicated in the question. Otherwise a mere count(finaldata) should suffice..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:Nathan Riley
ID: 23625540
I just tested in query analyzer a minute ago against a tabel of mine, I must have done something different then
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 23625579
SELECT SUM(Total) AS GrandTotal
FROM (
SELECT Count(FinalData) AS Total FROM Data
) AS derived
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 23625596
SELECT COUNT(FINALDATA)  AS Total
FROM Data
COMPUTE SUM(COUNT(FINALDATA))

This gives me the same result
34
78
44
90
35

0
 
LVL 41

Expert Comment

by:Sharath
ID: 23625643
What is your expected result? Are you looking for this? Do yu have GROUP BY clause in your original query?

SELECT SUM(Total) FROM (SELECT COUNT(FINALDATA) AS Total FROM Data ) T1
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

809 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