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

后端 未结 3 1367
栀梦
栀梦 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:42

        ;WITH    CTE1 ( MarksObtained )
                  AS ( SELECT   SUM(MarksObtained) AS MarksObtained
                       FROM     tbAnswers
                       WHERE    QID IN ( SELECT QID
                                         FROM   tbQuestions
                                         WHERE  ExamID = 2 )
                     ),
                CTE2 ( MaxMarks )
                  AS ( SELECT   SUM(Marks) AS MaxMarks
                       FROM     tbQuestions
                       WHERE    ExamID = 2
                     )
            SELECT  MaxMarks,MarksObtained
            FROM    CTE1 ,
                    CTE2
    

提交回复
热议问题