出什么问题了?
SELECT distinct a.number,a.code,a.day - (b.Miktar - b.GonderilenMiktar) AS sonuc
FROM dbo.T07 a, T05 b WHERE a.number=b.number and a.code=b.code
and sonuc!=-1
错误:
无效的列名“ sonuc”。
答案 0 :(得分:1)
您可以修改
SELECT distinct a.number,a.code,a.day - (b.Miktar - b.GonderilenMiktar) AS sonuc
from dbo.T07 a join
T05 b
on a.number = b.number and a.code = b.code
where (b.Miktar - b.GonderilenMiktar)!= -1
答案 1 :(得分:0)
列别名不能在相同的select
或where
或其他子句中使用。您需要CTE或子查询:
select distinct number, code, sonuc
from (select a.number, a.code,
a.day - (b.Miktar - b.GonderilenMiktar) as sonuc
from dbo.T07 a join
T05 b
on a.number = b.number and a.code = b.code
) ab
where sonuc <> -1;
注意:
FROM
子句中使用逗号。 始终使用正确的,明确的,标准 JOIN
语法。<>
。