简单的2条图表

时间:2011-07-12 11:50:28

标签: c# asp.net sql charts

我想使用图表控件..我想在其上显示两个小节。一个用于正确答案,另一个用于用户给出的总答案。

这就是我的SQLDataSource:

    <asp:SqlDataSource ID="AllQuestionStatistics" runat="server" 
                ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>" SelectCommand=" DECLARE @TotalQuestions int;
DECLARE @CorrectQuestions int;

SELECT @CorrectQuestions = COUNT( WiningComment) 
    FROM Threads
    WHERE WiningComment IN (SELECT CommentsID
    FROM Comments
    WHERE  UsersID=@UserID)


    SELECT @TotalQuestions =  COUNT(CommentsID)
    FROM  Comments
    WHERE  UsersID=@UserID

Select @CorrectQuestions as 'WinningAnswers',
@TotalQuestions as 'TotalAnswers',

" onselecting="AllQuestionAskedDataSource_Selecting">
                <SelectParameters>
                    <asp:Parameter Name="TotalQuestions" />
                    <asp:Parameter Name="CorrectQuestions" />
                    <asp:Parameter Name="UserID" />
                </SelectParameters>
            </asp:SqlDataSource>

我想将TotalQuestions作为一个条形,将CorrectQuestions作为另一个条形。我如何实现呢?

1 个答案:

答案 0 :(得分:0)

这是一种将查询作为一个

的方法
SELECT COUNT(*) AS TotalQuestions -- count all comments
 , SUM(CASE WHEN CommentId = WiningComment THEN 1 ELSE 0 END) CorrectQuestions -- if comment = wining comment add 1 else 0
 , SUM(CASE WHEN CommentId = WiningComment THEN 0 ELSE 1 END) WrongQuestions -- if comment = wrong comment add 1 else 0
FROM  Comments -- get all comments for user in where clause
LEFT JOIN Threads ON Comments.ThreadId = Threads.Id -- join with the thread table
WHERE  UsersID=@UserID

这与帖子I need help with subtracting the results from two queries有关吗?​​