我正在使用数据库超文件客户端/服务器使用windev 17。
我有一个名为 Operation 的表,其中包含列(accountNumber、date、amount、operationType)。
operationType 可以取两个值:“payment”和“withdrawal”。
我想选择一个帐户中完成的操作列表,我的列表应该显示 5 列:日期、帐户编号、金额、操作类型和余额。
最后一列(余额)应该是在当前日期之前完成的所有类型为“付款”的操作的总和与当前日期之前完成的所有操作的总和之间的差值,类型为“提款”
我尝试以下sql代码
SELECT date, accountNumber, operationType, deposits - withdrawals AS balance
FROM Operations o INNER JOIN (
SELECT accountNumber, date, SUM(amount) AS withdrawals
FROM Operaions
WHERE operationType = 'withdrawal'
GROUP BY accountNumber
) a ON (o.accountNumber = a.accountNumber AND a.date<=o.date)
INNER JOIN (
SELECT accountNumber,date, SUM(amount) AS deposits
FROM Operations
WHERE operationType = 'deposit'
GROUP BY accountNumber
)b ON (o.accountNumber = b.accountNumber AND b.date<=o.date)
但查询不显示任何值。
我也试过这个
SELECT date as dateop, accountNumber, operationType, deposits - withdrawals AS balance
FROM Operations o INNER JOIN (
SELECT accountNumber, date, SUM(amount) AS withdrawals
FROM Operaions
WHERE operationType = 'withdrawal' AND date<=dateop
GROUP BY accountNumber
) a ON o.accountNumber = a.accountNumber
INNER JOIN (
SELECT accountNumber,date, SUM(amount) AS deposits
FROM Operations
WHERE operationType = 'deposit' AND date<=dateop
GROUP BY accountNumber
)b ON o.accountNumber = b.accountNumber
但我收到一条错误消息,告诉我 dateop 列不存在。
请问我需要帮助