查询源表的特定数据,将结果作为新表更新到目标表中

<update id="updateMemberAdd">
        UPDATE member.es_member m ,

            (SELECT ship_province_id,ship_city_id,ship_county_id,ship_town_id,ship_province,ship_city,ship_county,ship_town,member_id FROM trade.es_order o

            where
                <if test="memberId != null and memberId != ''">
                    o.member_id = #{memberId}
                </if>
            GROUP BY ship_province

            order by count(ship_province) desc

            LIMIT  1) res

        set m.province_id=res.ship_province_id, m.city_id=res.ship_city_id, m.county_id=res.ship_county_id, m.town_id=res.ship_town_id, m.province=res.ship_province, m.city=res.ship_city, m.county=res.ship_county, m.town=res.ship_town

        WHERE res.member_id = m.member_id
    </update>

第一次在mapper里写update:将用户购买最多使用的地址更新到member表里,这里是把子查询结果当作一张新表res,将res拿来更新m表,要注意的是 语法竟然是”update表1,表2...“,这里的逗号不能漏掉,这里底层的逻辑是拿逗号分割的吗

代码报错了:

2022-08-29 09:46:02,641 ERROR [http-nio-8005-exec-2] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error preparing statement.  Cause: java.lang.ClassCastException: org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment cannot be cast to org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment] with root cause
java.lang.ClassCastException: org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment cannot be cast to org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.ExpressionSegment

这句sql在mysql里写就没问题,但是用mybatis出现问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值