想必各位在开发过程中一定使用过:统计的功能,用到了很多SQL的函数,于是就直接写在Mapper文件中了;
比如:
member_num,MAX(ID) AS newestLoanID,MIN (ID) AS earlyLoanID,SUM(applied_amount) AS sumLoansAmount,status
select
member_num,MAX(ID) AS newestLoanID,MIN (ID) AS earlyLoanID,SUM(applied_amount) AS sumLoansAmount,status
from credit_loan_record ......
看似没有啥问题;
执行的时候报错了!
java.lang.RuntimeException: org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION credit_center.MIN does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
于是拿到mysql的客户端工具来执行!同样的错误!!
那么可想而知,真的是SQL的问题了,于是我们美化一下SQL
SELECT
member_num,
MAX( ID ) AS newestLoanID,
MIN( ID ) AS earlyLoanID,
SUM( applied_amount ) AS sumLoansAmount,
STATUS
FROM
credit_loan_record
WHERE
member_num = 18810875228
AND deleted = 0
竟然通过了!!!
等等!好像异常里面有提示! FUNCTION credit_center.MIN does not exist.
"MIN (ID) AS earlyLoanID"——竟然有空格
优化之后:MIN( ID ) AS earlyLoanID,
然后就不报错! min(id) != min (id) 其实就是对于数据库的一些已定义的函数在使用的时候,没有按照必定的表达式进行使用,尤其是带有空格“MIN (id)”等当时,经常会有一些 方法不存在的错误信息,这个时候就一定要检查一下了。 所以,如果以后提示:FUNCTION XXXXX.MIN does not exist.时候,记得看看是不是有空格啊!或者使用数据库自带的函数存在使用错误的问题。