我有以下数据:
http://i.imgur.com/e4d8M8V.png?1
第一个表被标记为“提供”,第二个表被标记为“讲师”
我想把所有没有教师证的教授的薪水加起来。
我首先做的是生成一个表,其中包含我需要的数据:

select distinct i.InstructorID, i.Salary
from Instructor i
where i.InstructorID NOT IN (select o.InstructorID from Offering o);

这给了我想要的结果:
http://i.imgur.com/rkFKseX.png?1
然后,我想添加这两个工资,并将结果显示在一个工资列中。我试过这样的代码:
$MySQL:> select sum(i.Salary)
from Instructor i
where i.Salary in ( select distinct i.InstructorID, i.Salary
from Instructor i
where i.InstructorID NOT IN (select o.InstructorID from Offering o));

并获取“SQLException:java.sql.SQLException:Operand应该包含1 co”。但是,我不确定如何将上一个查询的结果包含到一列中。我的看法是,如果我要把名单上的所有工资加起来,我只是做了一个不同的工资,它只会返回三个工资,而不是八个工资,所以这样做对我的情况也是错误的。
如何添加生成的两列,是否有比使用的方法更容易完成目标的方法?

最佳答案

您可以使用子查询。它们的描述如下article

10-07 17:49