Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of the total counted

Status
Not open for further replies.

camillaj

Programmer
Sep 18, 2003
31
0
0
AU
I am giving a report on DB data.

For each "level", i.e. 1-5, I retrieve how many selected each of them, such as:

SELECT LikertLevel, Count(*) AS CountSelected FROM Response WHERE QuestId=" & Session("QuestId") & " And AlternativeId=" & altIdList(i) & " GROUP BY LikertLevel

With this I get:
1 5
2 3
3 4

which means 5 selected level1, 3 selected level 2 etc...

Can I in the same query also retrieve the sum of the 'CountSelected' field, (5+3+4)? I tried with an extra
SUM(CountSelected) in the Select, but that didn't work.

I need this to calcualte the percentage. I can of course retrieve all values as above, store them in a list and then add them, but that seems unnecessary.

Thanks for your help :)
 
[tt]SELECT LikertLevel, Count(*) AS CountSelected
FROM Response
WHERE QuestId=" & Session("QuestId") & "
And AlternativeId=" & altIdList(i) & "
GROUP BY LikertLevel
UNION ALL
SELECT LikertLevel, Count(*)
FROM Response
WHERE QuestId=" & Session("QuestId") & "
And AlternativeId=" & altIdList(i) & "
[/tt]

rudy
 
ah, typo, sorry

[tt]SELECT LikertLevel, Count(*) AS CountSelected
FROM Response
WHERE QuestId=" & Session("QuestId") & "
And AlternativeId=" & altIdList(i) & "
GROUP BY LikertLevel
union all
SELECT null, Count(*) AS CountSelected
FROM Response
WHERE QuestId=" & Session("QuestId") & "
And AlternativeId=" & altIdList(i) & "
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top