开始
先来写sql语句
涉及到这两张表的关联
等待,待评价的订单。
‘
select
count(1)
from
orders o
left join
order_status os
on
o.id=os.order_id
where
o.user_id='21011270605KYX8H'
and os.order_status=40
and o.is_comment=0
状态改成10,然后下面是否评论注释掉。查询到3条数据
select
count(1)
from
orders o
left join
order_status os
on
o.id=os.order_id
where
o.user_id='21011270605KYX8H'
and os.order_status=10
SQL 查找是否“存在“,别再 count 了,很耗费时间的!
https://my.oschina.net/u/4192546/blog/4964639
后端
xml内写sql
直接返回int
<select id="queryMyOrderStatusCounts" parameterType="Map" resultType="int">
select
count(1)
from
orders o
left join
order_status os
on
o.id=os.order_id
where
o.user_id=#{paramsMap.userId}
and os.order_status=#{paramsMap.orderStatus}
<if test="paramsMap.isComment != null">
and o.is_comment=#{paramsMap.isComment}
</if>
定义接口
public int queryMyOrderStatusCounts(@Param("paramsMap") Map<String,Object> map);