我在下面有这个存储过程,它允许我选择一个问题ID并列出用户名和他们的答案。
我如何更改它,以便只显示带有新列名为total 的问题ID,如下所示
CREATE PROCEDURE dbo.report
@Question_ID varchar(5)
AS
SELECT * FROM submit_Answer
WHERE Question_ID=@Question_ID
谢谢!
答案 0 :(得分:1)
使用此方法为每个Question_ID获取一行,并在总计列中回答并计算出现次数。
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