MyBatis Cause: java.sql.SQLSyntaxErrorException: FUNCTION xxx.sum does not exist.解决方案

最近在使用Mybatis的时候,在做后台查询购物车的商品总数的时候,用到sum()函数,废话不多数,代码如下:

<select id="selectCartProductCountByUserId" parameterType="int" resultType="int">
    select IFNULL(sum (quantity),0) as count
    from tb_cart
    where user_id = #{userId}
</select>

在做接口测试的时候,报错如下:

Cause: java.sql.SQLSyntaxErrorException: FUNCTION shopping-mall.sum does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual.....(组要错误我已经标出),而这时候我回去检查我的sql,也没发现错误,很苦恼,这时候无意中发现我的 IFNULL(sum (quantity),0)的sum()函数后面多了一个空格,满怀期待的去掉空格尝试一便,发现结果成功了,结果很明显,多了一个空格,记得不要在sum后面加空格,这时候去掉空格之后的sql应该为:

  <select id="selectCartProductCountByUserId" parameterType="int" resultType="int">
    select IFNULL(sum(quantity),0) as count
    from tb_cart
    where user_id = #{userId}
  </select>

接口测试成功:

如果文章对你有帮助请点赞2333

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值