0

I have two operations for SQL (which are working properly, seperately):

SELECT SUM(Salary) AS StutorSum
FROM Stutor;

SELECT SUM(Salary) AS StudentAssistentSum
FROM StudentAssistent;

`

But the problem is that I cannot combine them. Eventually I want three columns as a result:

  1. Column with the StutorSum
  2. Column with the StudentAssistentSum
  3. Column with the total of both

However I cannot make this happen, I tried a lot of things, searched on the internet, but nothing worked.

Could anyone help me?

Regards, Joren

jorenwouters
  • 105
  • 1
  • 1
  • 8
  • What database are you using? Sql Server? MySql? Access? Oracle? Postgresql? And what is the key column for these tables (StudentID, Name, etc)? – Joel Coehoorn Nov 01 '16 at 22:56

2 Answers2

0
SELECT 
    SUM(Salary) AS StutorSum,
    (SELECT SUM(Salary) FROM StudentAssistent) AS StudentAssistentSum,
    (SELECT SUM(Salary) FROM Stutor) + (SELECT SUM(Salary) FROM StudentAssistent) As Total
FROM Stutor;
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
0

I would recommend putting the queries in the FROM clause and doing the arithmetic:

SELECT t.StutorSum, a.StudentAssistentSum,
       (t.StutorSum + a.StudentAssistentSum)
FROM (SELECT SUM(Salary) AS StutorSum
      FROM Stutor
     ) t CROSS JOIN
     (SELECT SUM(Salary) AS StudentAssistentSum
      FROM StudentAssistent
     ) a;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786