SELECT `t`.`operUserName` AS `operUserName`, `t`.`operationId` AS `operationId`, `t`.`operUser` AS `operUser`, `t`.`operDate` AS `operDate`, `t`.`serviceName` AS `serviceName`, `t`.`date` AS `date`, count(0) AS `num` FROM ( SELECT `es`.`operUserName` AS `operUserName`, `es`.`operationId` AS `operationId`, `es`.`operDate` AS `operDate`, `es`.`serviceName` AS `serviceName`, `es`.`operUser` AS `operUser`, date_format( from_unixtime((`es`.`operDate` / 1000)), '%Y-%m-%d %H:%i:%s' ) AS `date` FROM `eslog_service_20230307` `es` ORDER BY `es`.`operDate` DESC ) `t` GROUP BY `t`.`serviceName`, `t`.`operUser`改为每人每天操作次数统计
时间: 2023-06-12 20:08:11 浏览: 139
为了实现每人每天操作次数统计,需要对原有的SQL语句进行修改。具体修改如下:
```
SELECT
`t`.`operUserName` AS `operUserName`,
`t`.`operationId` AS `operationId`,
`t`.`operUser` AS `operUser`,
`t`.`operDate` AS `operDate`,
`t`.`serviceName` AS `serviceName`,
DATE_FORMAT(FROM_UNIXTIME((`t`.`operDate` / 1000)), '%Y-%m-%d') AS `date`,
COUNT(0) AS `num`
FROM
(SELECT
`es`.`operUserName` AS `operUserName`,
`es`.`operationId` AS `operationId`,
`es`.`operDate` AS `operDate`,
`es`.`serviceName` AS `serviceName`,
`es`.`operUser` AS `operUser`
FROM
`eslog_service_20230307` `es`
ORDER BY
`es`.`operDate` DESC) `t`
GROUP BY
`t`.`serviceName`,
`t`.`operUser`,
DATE_FORMAT(FROM_UNIXTIME((`t`.`operDate` / 1000)), '%Y-%m-%d')
```
修改后的SQL语句在原有的基础上添加了一个日期转换函数,将操作时间转换为日期,并将日期添加到GROUP BY子句中,以实现每人每天操作次数统计的功能。
阅读全文