MySQL运行平衡视图错误

时间:2016-12-03 19:22:30

标签: mysql

您好我正在尝试在MySQL中创建一个视图,但我收到语法错误#1064,即

1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册>在'SET @csum:= 0附近使用正确的语法;在第3行

在这里我如何修复此变量问题任何解决方案或替代方法来轻松计算运行平衡

这是我的代码

SET @csum := 0;
SELECT
tblleasesalesschedule_details.LeaseSaleID,
tblleasesalesschedule_details.ScheduleSr,
tblleasesalesschedule_details.InstallmentName,
tblleasesalesschedule_details.InstallmentSr,
tblleasesalesschedule_details.ScheduleDate,
tblleasesalesschedule_details.Amount,
IFNULL(tblleasesalespayment.Amount, 0) AS AmountPaid,
(coalesce(tblleasesalesschedule_details.Amount, 0) - coalesce(tblleasesalespayment.Amount, 0)) As BalanceAmount,
(@csum := @csum + (coalesce(tblleasesalesschedule_details.Amount, 0) - coalesce(tblleasesalespayment.Amount, 0))) as RunningBalance,
tblleasesalespayment.PaymentDate
FROM
tblleasesalespayment
RIGHT JOIN tblleasesalesschedule_details ON tblleasesalesschedule_details.InstallmentSr = tblleasesalespayment.InstallmentSr
WHERE
tblleasesalesschedule_details.PayDate < NOW();

0 个答案:

没有答案