81,092
社区成员
发帖
与我相关
我的任务
分享
<select id="selectPurchaseCountList" parameterType="java.util.HashMap" resultType="com.xx.core.vo.DealCountVo">
select
sc.CUSTOMER_ID as customerId,
count(distinct so.ID) as dealCount
from sp_customer sc left join sp_order so on so.RELEASE_ID = sc.CUSTOMER_ID
left join sp_user su on su.ID = sc.CUSTOMER_ID
where sc.USER_ID = #{userId} and sc.CUSTOMER_TYPE = #{customerType}
and so.IS_PURCHASE_ORDER = 1 and so.RECIPIENT_ID = #{userId}
and su.STATE != 3
and so.STATE = 8
group by sc.CUSTOMER_ID
order by sc.CREATE_TIME desc
limit #{startIndex},#{pageSize}
</select>
至于多表怎么关联,就靠关联字段进行关联,比如A表表示学生,里面有个字段CLASS_ID表示所在班级的ID,B表示班级表,主键是班级ID,select * from A, B where A.CLASS_ID = B.ID,这样就可以关联了