2017-07-29 38 views

回答

1

在SQL Server 2012+,你可以使用一個累積和加減:

select t.*, 
     (salary - sum(deduct) over (partition by employee order by sn)) as calc 
from t; 
+0

在SQL Server 2012: - 語法錯誤近的順序。 –

+0

@Rahulpatel。 。 。如果您使用的是SQL Server 2012,請檢查您的兼容性:https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level。 –