场景

某业务记录表中记录的所有员工的某记录。

要实现统计截止到现在为止的符合某些条件的人数。实现效果类似如下

 

 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

比如查询本月的符合条件的人数

    <select id="selectCurrentMonthNum" resultType="Integer">
        SELECT count(*) from
            (
            select gh from dp_ddjl
            where sh =1 and sfcl =1 and htsfcl =1
            and date_format(ddsj,'%y%m') = date_format(#{currnetMonth},'%y%m')
            GROUP BY gh
            ) a
    </select>

切记外层查询时要给设置别名。

其中gh是工号是作为人员分类的标志。

然后currentmonth是传递的当前时间,截取月份就行。

同理如果是要统计截止到今天之前的符合条件的人数

    <select id="selectHtDqNum"  resultType="Integer">
        SELECT
        count( * )
        FROM
        (
        SELECT
        gh
        FROM
        ht_htcx
        WHERE
        isdelete = 0
        AND  date_format(#{today}, '%y%m%d' ) >date_format( jssj, '%y%m%d' )
        GROUP BY
        gh
        ) a
    </select>

 

posted on 2020-08-28 09:42  霸道流氓  阅读(676)  评论(0编辑  收藏  举报