一条sql语句查询多个条件的写法

1.一条sql语句查询多个条件的写法

(1)sql语句的使用

SELECT p1.count1 AS todayAdd,p2.count2 AS todayReturns,p3.count3 AS sameMonthAdd,p4.count4 AS lastMonthAdd
        FROM (SELECT COUNT(create_time)count1 FROM project_info WHERE TO_DAYS(create_time)=TO_DAYS(SYSDATE())) AS p1,
        (SELECT COUNT(go_back_time) count2 FROM project_info WHERE TO_DAYS(go_back_time)=TO_DAYS(SYSDATE())) AS p2,
        (SELECT COUNT(create_time) count3 FROM project_info WHERE DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )) AS p3,
        (  SELECT COUNT(create_time) count4	FROM project_info WHERE PERIOD_DIFF( DATE_FORMAT( NOW( ) , '%Y%m' ) , DATE_FORMAT( create_time, '%Y%m' ) ) =1)AS p4
    

(2)返回数据的实体类

@Data
public class NewsStatisticsDTO {
    @ApiModelProperty(name = "todayAdd",value = "今日新增信息")
    private Integer todayAdd;

    @ApiModelProperty(name = "todayReturns",value = "今日退回信息")
    private  Integer todayReturns;

    @ApiModelProperty(name = "sameMonthAdd",value = "当月新增信息")
    private Integer sameMonthAdd;

    @ApiModelProperty(name = "lastMonthAdd", value = "上月新增信息")
    private Integer lastMonthAdd;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值