Combine two different unrelated SQL queries( returning single column results) into one query result with two columns

后端 未结 3 1364
栀梦
栀梦 2021-01-29 03:37

I have two sql queries. In first I am returing total marks obtained and in other i am returning maximum marks . Now i want to combine both in single query for the purpose of ma

3条回答
  •  清酒与你
    2021-01-29 03:45

    Well, since the queries are unrelated, you can just throw them into the select:

    SELECT
       (
          select SUM(MarksObtained)  
          from tbAnswers where QID IN (
              Select QID from tbQuestions where ExamID = 2
          )
       ) as MarksObtained,
       (
           Select SUM(Marks)   
           from tbQuestions where ExamID = 2
       ) as MaxMarks
    

提交回复
热议问题