我需要过滤具有一些条件列的查询,如下所示:
SELECT
`c`.`fullname` AS `fullname`,
IFNULL(`c`.`new_ic`,`c`.`old_ic`) AS `Ic`,
`bla`.`loan_no` AS `Loan_No`,
`bla`.`total_loan_amt` AS `Total_Loan_Amt`,
`bla`.`monthly_installment` AS `Month_Inst_Amt`,
`bla`.`disb_date` AS `disb_date` FROM (`customers` `c`
JOIN `basic_loan_application` `bla`
ON ((`bla`.`customer_uid` = `c`.`customer_uid`)))
WHERE Ic LIKE '%800%' ORDER BY `bla`.`Basic_Loan_Application_Id` DESC LIMIT 0, 10
但我无法使用Ic字段并返回错误,如下所述:
Unknown column 'Ic' in 'where clause'
如果可能,我想尽量避免嵌套选择。
这个问题还有另一个解决方案吗?
答案 0 :(得分:0)
重复一下定义:
WHERE IFNULL(`c`.`new_ic`,`c`.`old_ic`) LIKE '%800%'
ORDER BY `bla`.`Basic_Loan_Application_Id` DESC
LIMIT 0, 10
或者,如果您愿意,可以使用MySQL扩展,允许您使用having
子句进行过滤(在本例中):
HAVING Ic LIKE '%800%'
ORDER BY `bla`.`Basic_Loan_Application_Id` DESC
LIMIT 0, 10