简化如下SQL:SELECT e.empName,e.ts,f.archermindNum,f.departureTimeMax,f.departureTimeMin,f.departureTimeAvg,f.departureTimeTotal from (select b.empName,count(clockDate) as ts from (SELECT empName,clockDate,COUNT(clockDate) from r_empmachineclock_data_analysis where clockDate between "2023-05-01" and "2023-05-30" GROUP BY empName,clockDate) b group by b.empName) e ,(select max(departureTime) as departureTimeMax,min(departureTime) as departureTimeMin,ROUND(avg(departureTime)) as departureTimeAvg,sum(departureTime) as departureTimeTotal,empName,archermindNum from r_empmachineclock_data_analysis where departureTime >0 and clockDate between "2023-05-01" and "2023-05-30" group by archermindNum) f where e.empName = f.empName
时间: 2024-02-20 22:01:57 浏览: 48
以下是简化后的SQL查询语句:
```
SELECT
e.empName,
e.ts,
f.archermindNum,
MAX(f.departureTime) AS departureTimeMax,
MIN(f.departureTime) AS departureTimeMin,
ROUND(AVG(f.departureTime)) AS departureTimeAvg,
SUM(f.departureTime) AS departureTimeTotal
FROM
(
SELECT
empName,
COUNT(clockDate) AS ts
FROM
(
SELECT
empName,
clockDate,
COUNT(clockDate)
FROM
r_empmachineclock_data_analysis
WHERE
clockDate BETWEEN "2023-05-01" AND "2023-05-30"
GROUP BY
empName,
clockDate
) b
GROUP BY
empName
) e
JOIN (
SELECT
empName,
archermindNum,
departureTime
FROM
r_empmachineclock_data_analysis
WHERE
departureTime > 0
AND clockDate BETWEEN "2023-05-01" AND "2023-05-30"
) f
ON e.empName = f.empName
GROUP BY
e.empName,
e.ts,
f.archermindNum
```
该查询使用了两个子查询,其中第一个子查询计算了每个员工的工作天数,第二个子查询计算了每个员工的出勤情况。通过内连接将这两个结果集合并,并使用GROUP BY对结果进行分组,以便得到每个员工的出勤统计信息。
阅读全文