我正在尝试过滤accountledger.transactiondate以仅返回那些在2019-04-01至2020-03-31之间的退款。
但是WHERE子句无效。
我将WHERE语句重新定位到了脚本中的许多位置;结果没有变化。
这是我的代码:
SELECT accountledger.CAMPUSCODE, accountledger.ID, students.FNAME,
students.LNAME, accountledger.PROGRAM,
accountledger.TRANSACTIONDATE, accountledger.TRANSACTIONAMOUNT,
accountledger.DESCRIPTION as 'ENR Desc',
accountledger.TRANSACTIONCODE as 'Inv Desc',
chart_accounts.NAME AS 'ChAcc Name'
FROM accountledger
INNER JOIN students
ON accountledger.ID = students.ID
INNER JOIN fees
ON accountledger.TRANSACTIONCODE = fees.NAME
INNER JOIN chart_accounts
ON fees.ACCOUNT = chart_accounts.ACCOUNT
WHERE accountledger.TRANSACTIONtype = 'I'
and accountledger.transactioncode like '%refund%'
or accountledger.transactioncode like '%paid to d-ed%'
or accountledger.transactioncode like '%paid to military%'
or accountledger.transactioncode like '%paid to voc rehab%'
and chart_accounts.NAME
AND accountledger.transactiondate BETWEEN 2019-04-01 AND 2020-03-31
GROUP BY accountledger.id
ORDER BY accountledger.TRANSACTIONDATE
我希望仅在WHERE语句的日期参数内发出的退款。但是,无论交易日期如何,脚本都会返回所有退款。
答案 0 :(得分:0)
使用正确的语法
accountledger.transactiondate BETWEEN CAST('2019-04-01' AS DATE) AND CAST('2020-03-31' AS DATE)
代替
accountledger.transactiondate BETWEEN 2019-04-01 AND 2020-03-31