2017-03-07 96 views
-1

我有一个具有以下字段的表:多部分标识符“IncomeExpenses.OperationId”无法绑定

OperationID, 
Date, 
TotalExpenses, 
TotalIncome 

我使用下面的SQL查询来获取基于TotalExpensesTotalIncome之间的区别指定OperationID

select 
    (select (Date) from IncomeExpenses) 
,(select (totalincome) from IncomeExpenses) 
-(select (totalexpenses) from IncomeExpenses) 
where IncomeExpenses.OperationId ='1' 

但是我得到这个错误:

The multi-part identifier "IncomeExpenses.OperationId" could not be bound

我可能会做错什么?

回答

0

如果这是SQL查询应该看起来像:

select Date, (totalincome - totalexpenses) as differencetotal 
from IncomeExpenses where OperationId ='1' 
2

为你写的子查询选择单独列的一些原因。外部查询中没有FROM子句,因此您不能编写引用任何表的where子句。为什么你不只是写作

select date, 
     totalincome-totalexpenses 
from IncomeExpenses 
where OperationId=1 
+0

谢谢你,这对我有效 –

相关问题