Simple 2 bars Chart
I want to use the chart control.. I want to present two bars on it. One for the right answers and another for the total answers given by the user.
Thats my 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>
开发者_JS百科 <asp:Parameter Name="TotalQuestions" />
<asp:Parameter Name="CorrectQuestions" />
<asp:Parameter Name="UserID" />
</SelectParameters>
</asp:SqlDataSource>
I want to presentTotalQuestions as one bar, and CorrectQuestions as another bar..How do I achieve so?
This is a way to make your query as one
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
Is this related with post I need help with subtracting the results from two queries ?
精彩评论