一句SQL统计多条数据

xml在这里插入代码片

<select id="getCount" resultType="com.pisolution.fare.dom.brandfare.model.dto.FareAndRuleCountDto">
   SELECT
       COUNT(IF(t.release_status != 0,1,null)) AS published,
       COUNT(IF(t.release_status = 1,1,null)) AS checkSuccess,
       COUNT(IF((t.release_status = 3 or t.release_status = 4),1,null)) AS checkFail,
       COUNT(IF(((t.release_status = 3 or t.release_status = 4)and t.status = 1),1,null)) AS failAndProcess,
       COUNT(IF(((t.release_status = 3 or t.release_status = 4)and t.status = 0),1,null)) AS failAndNotProcess
   FROM
       dom_fare_store t
   WHERE
       1 = 1
   <if test="vo != null and vo != ''">
       <if test="vo.startTime!= null">
           AND  t.release_time &gt;= #{vo.startTime}
       </if>
       <if test="vo.endTime!= null">
           AND  t.release_time &lt;= #{vo.startTime}
       </if>
       <if test="vo.userId!= null and vo.userId != ''">
           AND  t.creator_id = #{vo.userId}
       </if>

   </if>

</select>

mapper

@Mapper
public interface RuleStoreMapper extends BaseMapper<RuleStore> {
    FareAndRuleCountDto getCount(@Param("vo") HomeQueryVo vo);
}

实体

@Data
public class FareAndRuleCountDto {
    @ApiModelProperty("已发布")
    private int published;

    @ApiModelProperty("校验成功")
    private int checkSuccess;

    @ApiModelProperty("校验失败")
    private int checkFail;

    @ApiModelProperty("失败已处理")
    private int failAndProcess;

    @ApiModelProperty("失败未处理")
    private int failAndNotProcess;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值