I’m making a survey-applican with winforms and VB. This is the SQL I got so far to show statistics:
SELECT
tblAlt.altText,
Count(tblAnswers.answerID)
FROM tblAlt
LEFT JOIN tblAnswers ON (tblAlt.altId = tblAnswers.altID)
WHERE tblAlt.questionID = " & CInt(questionID) & "
GROUP BY tblAlt.altText;
This returns each alternatives for a question, and how many answered them. Is there a way I can count how many answered in total with the same SQL-query?
Tables involved are:
_______________ _______________ ___________ _______________
|_tblUsers____| |_tblAnswers___| |_tblAlt__| |_tblQuestion_|
| userID | | answerAltID | | altID | | questID |
| username | | userID | | altText | | questText |
|_____________| |______________| |_questID_| |_____________|
Any help would be appreciated!
This is what I used in the end:
SELECT
tblAlt.altText,
Count(tblAnswers.answerID),
(SELECT COUNT(answerID) FROM tblAnswers, tblAlt
WHERE tblAnswers.answerAltID = tblAlt.altID
AND tblAlt.questID = " & CInt(questionID) & ") as total_count
FROM tblAlt
LEFT JOIN tblAnswers ON (tblAlt.altId = tblAnswers.altID)
WHERE tblAlt.questID = " & CInt(questionID) & "
GROUP BY tblAlt.altText;
you can use an subquery to do this, something like:
Some Resources:
http://beginner-sql-tutorial.com/sql-subquery.htm
http://www.1keydata.com/sql/sql-subquery.html