2011-07-12 12 views
0

私はチャートコントロールを使用したい。私はそれに2つのバーを表示したい。 1つは正しい答えに、もう1つはユーザーが与えた答えの合計です。私のSqlDataSourceザッツシンプルな2つの棒グラフ

<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 [email protected]) 


    SELECT @TotalQuestions = COUNT(CommentsID) 
    FROM Comments 
    WHERE [email protected] 

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> 

私は1つのバーとしてpresentTotalQuestionsにしたい、と別のbar..HowなどCorrectQuestions私はそう達成していますか?

答えて

0

これは、1つの

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 [email protected] 

としてクエリを作るための方法は、これはポストI need help with subtracting the results from two queriesと関連しているのですか?

関連する問題