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

sql语句的学习 专栏收录该内容
5 篇文章 0 订阅

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

 

  • 2
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值