我正在尝试对自定义报告运行查询,该报告应该根据指定日期范围内的贷款还款类型为符合五个条件的客户返回数据。标准是Salary Deduction
、Bank Standing Order
、Self-Pay
和Post Dated Cheques
。Bank Debit
结果应返回来自指定的每个条件的客户端数量的计数。但是,这不是我目前得到的结果;这些查询正在针对这个软件Mambu进行测试。结果取决于一个customfield
和customfieldvalue
(它指定要使用的还款类型)列。这就是我期望的结果应该是这样的:
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| LoanProduct | RepaymentType | Clients |
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| JUMPSTART LOAN WEEKLY | Self-Pay | 35 |
------------------------------------------------------
| PAYDAY LOAN MONTHLY | Salary Deduction | 5 |
------------------------------------------------------
| MICRO-BIZ LOAN | Bank Debit | 26 |
------------------------------------------------------
| PAYDAY LOAN WEEKLY | Self-Pay | 1 |
.......
and so on ...
到目前为止我尝试过的解决方案:
QUERY #1:
对于这个查询,我只是想找回所有的客户,而不需要计算特定的还款类型;它适用于那种情况。
SELECT CONCAT(client.FIRSTNAME, ' ', client.LASTNAME) AS Client,
CONCAT(user.FIRSTNAME, ' ', user.LASTNAME) AS Originator,
loanproduct.PRODUCTNAME AS LoanProduct, customfieldvalue.VALUE AS RepaymentType
FROM client, user, customfieldvalue, loanaccount
INNER JOIN loanproduct ON loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY
WHERE client.ASSIGNEDUSERKEY = user.ENCODEDKEY
AND loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY
AND customfieldvalue.VALUE = "Bank Debit"
AND loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31"
GROUP BY user.LASTNAME, client.LASTNAME
QUERY #1.1
在上面
添加 anOR
不会产生任何结果:
SELECT CONCAT(client.FIRSTNAME, ' ', client.LASTNAME) AS Client,
CONCAT(user.FIRSTNAME, ' ', user.LASTNAME) AS Originator,
loanproduct.PRODUCTNAME AS LoanProduct, customfieldvalue.VALUE AS RepaymentType
FROM client, user, customfieldvalue, loanaccount
INNER JOIN loanproduct ON loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY
WHERE client.ASSIGNEDUSERKEY = user.ENCODEDKEY
AND loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY
AND customfieldvalue.VALUE = "Bank Debit" OR customfieldvalue.VALUE = "Self-Pay"
AND loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31"
GROUP BY user.LASTNAME, client.LASTNAME
QUERY #2
我什至尝试使用CASE
语句执行此操作,但它只返回Clients
as的所有行NULL
并且需要大约 12.1 秒才能完成。
SELECT
loanproduct.PRODUCTNAME AS LoanProduct, customfieldvalue.VALUE AS RepaymentType,
CASE
WHEN customfieldvalue.VALUE = "Salary Deduction" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
WHEN customfieldvalue.VALUE = "Bank Standing Order" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
WHEN customfieldvalue.VALUE = "Self-Pay" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
WHEN customfieldvalue.VALUE = "Post Dated Cheques" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
WHEN customfieldvalue.VALUE = "Bank Debit" THEN COUNT(CONCAT(client.FIRSTNAME, ' ', client.LASTNAME))
END AS Clients
FROM client, user, customfieldvalue, loanaccount
INNER JOIN loanproduct ON loanaccount.PRODUCTTYPEKEY = loanproduct.ENCODEDKEY
WHERE client.ASSIGNEDUSERKEY = user.ENCODEDKEY
AND loanaccount.ACCOUNTHOLDERKEY = client.ENCODEDKEY
AND loanaccount.DISBURSEMENTDATE BETWEEN "2012-01-01" AND "2013-01-31"
GROUP BY user.LASTNAME, client.LASTNAME
我在这里做错了什么,这阻止了我得到想要的结果?提前致谢。