作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要过滤具有以下条件列的查询:
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'
如果可能的话,我想尽量避免嵌套选择。
这个问题还有其他解决办法吗?
最佳答案
只需重复定义:
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
关于Mysql 选择别名列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24878448/
我是一名优秀的程序员,十分优秀!