当前使用版本(必须填写清楚,否则不予处理)
3.2.0
该问题是怎么引起的?(最新版上已修复的会直接close掉)
在SQL中使用 group by date()
重现步骤
在SQL中使用 group by date()
报错信息
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.ClassCastException: net.sf.jsqlparser.expression.Function cannot be cast to net.sf.jsqlparser.schema.Column
Cause: java.lang.ClassCastException: net.sf.jsqlparser.expression.Function cannot be cast to net.sf.jsqlparser.schema.Column
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:78)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
at com.sun.proxy.$Proxy146.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:158)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:76)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:61)
at com.sun.proxy.$Proxy188.querySendCount(Unknown Source)
Comment From: nieqiurong
要不把你的完整SQL语句发出来看看.
Comment From: stjava
select ifnull(count(1), 0) from ( select count(1) FROM record_1 WHERE user_id = #{userId} AND shop_id = #{shopId} GROUP BY date(date_time1) ) t1
Comment From: timandy
ifnull 加个别名试试
select ifnull(count(1), 0) yourColumnName
from (
select count(1)
FROM record_1
WHERE user_id = #{userId}
AND shop_id = #{shopId}
GROUP BY date(date_time1)
) t1
Comment From: nieqiurong
问题还是在group by 函数列的问题,并非前面的语句
Comment From: stjava
是的,是函数列的问题。如果不用函数,用一个字段来group by 就没有问题。
Comment From: miemieYaho
ClassCastException 发生在哪个位置? 或者说你用了哪些插件?