<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cyksj.mapper.ClaudeCodeUserRenewExpiryRecordMapper">

    <select id="getOtherRenewSku" resultType="com.cyksj.model.entity.ClaudeCodeUserRenewExpiryRecord">
        select orr.* from (select * from claude_code_user_renew_expiry_record where order_id != #{orderId}
        and is_valid = 0
        and user_id in
        <foreach collection="userIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>) orr inner join order_don o on o.id = orr.order_id
        and o.status not in ('close','noPayment','refund')
        and o.order_type = 2 and o.relation_id = #{relationId}
        inner join goods_don_sku sku on sku.id = o.sku_id
        order by sku.months desc,sku.code_points desc
        limit 1
    </select>
</mapper>