结合两个表中的两个SUM运算

时间:2016-11-01 22:53:41

标签: sql combiners

我有两个SQL操作(分别正常工作):

SELECT SUM(Salary) AS StutorSum
FROM Stutor;

SELECT SUM(Salary) AS StudentAssistentSum
FROM StudentAssistent;

`

但问题是我无法将它们结合起来。 最终我想要三列:

  1. StutorSum的专栏
  2. 包含StudentAssistentSum的列
  3. 包含两者总数的列
  4. 然而,我无法做到这一点,我尝试了很多东西,在互联网上搜索,但没有任何效果。

    有人可以帮助我吗?

    此致 净莲

2 个答案:

答案 0 :(得分:0)

<script>
        window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
        ga('create', 'UA-XXXX-1', 'auto');
        ga('require', 'urlChangeTracker', {
        shouldTrackUrlChange: function(newPath, oldPath) {
            newPath = newPath.split('?')[0];
            oldPath = oldPath.split('?')[0];
            return newPath != oldPath;
          }
        });
        ga('send', 'pageview');
        </script>
        <script async src='https://www.google-analytics.com/analytics.js'></script>
        <script async src="https://cdnjs.cloudflare.com/ajax/libs/autotrack/0.6.4/autotrack.js"></script>

答案 1 :(得分:0)

我建议将查询放在FROM子句中并进行算术运算:

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;