Link to home
Start Free TrialLog in
Avatar of RecipeDan
RecipeDan

asked on

Count Data then Sum Rows

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?
 
Avatar of reb73
reb73
Flag of Ireland image

Add the following at the end of the SELECT statement -

COMPUTE SUM(COUNT(FINALDATA))
Avatar of Nathan Riley

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

Open in new window

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..
I just tested in query analyzer a minute ago against a tabel of mine, I must have done something different then
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RecipeDan
RecipeDan

ASKER

SELECT COUNT(FINALDATA)  AS Total
FROM Data
COMPUTE SUM(COUNT(FINALDATA))

This gives me the same result
34
78
44
90
35

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