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;
}