Reputation: 63
I have this stored procedure below, it allows me to select a question id and list the username and their answer.
How would i change it so it only shows me the question id with a new column called total as below
CREATE PROCEDURE dbo.report
@Question_ID varchar(5)
AS
SELECT * FROM submit_Answer
WHERE Question_ID=@Question_ID
Thanks!
Upvotes: 2
Views: 175
Reputation: 138960
Use this to get one row for each Question_ID and Answer and count the number of occurrences in column Total.
CREATE PROCEDURE dbo.report
@Question_ID varchar(5)
AS
SELECT Question_ID,
Answer,
COUNT(*) as Total
FROM submit_Answer
WHERE Question_ID=@Question_ID
GROUP BY Question_ID,
Answer
Upvotes: 1