简体   繁体   English

如何计算每个员工每个项目的工作时间

[英]How to calculate work hours per project per employee

I have a PHP form that inputs empID, projectNumber, and clock-in/clock-out time-stamp into a MySQL table like this: 我有一个PHP表单,将empID,projectNumber和Clock-in / Cout时间戳输入到MySQL表中,如下所示:

Having no reputation, I can't post image, so take a look here: screenshot http://mailed.in/timecard/ss1.jpg 没有声誉,我无法发布图片,因此请在此处查看: 屏幕快照http://mailed.in/timecard/ss1.jpg

I need help in generating a report that looks like this: screenshot http://mailed.in/timecard/ss2.jpg 在生成如下所示的报告时,我需要帮助: 屏幕快照http://mailed.in/timecard/ss2.jpg

Can I do this entirely in MySQL? 我可以完全在MySQL中执行此操作吗? How? 怎么样?

This may help you : 这可以帮助您:

SELECT 
    empID AS EmpID, 
    projectNumber AS ProjectNumber, 
    DATE(clocktime) AS StartDate,  
    TIMEDIFF(
      (SELECT max(clocktime) from tableName where DATE( `clocktime` ) = CURDATE( )), 
      (SELECT min(clocktime) from tableName where DATE( `clocktime` ) = CURDATE( ))
    ) AS WorkHours
FROM `tableName`
WHERE 
DATE( `clocktime` ) = CURDATE( )
GROUP BY empID

Try this query - 试试这个查询-

CREATE TABLE table_proj (
  empid INT(11) DEFAULT NULL,
  projectnumber INT(11) DEFAULT NULL,
  clocktime DATETIME DEFAULT NULL
);

INSERT INTO table_proj VALUES 
  (1, 1, '2011-09-27 10:02:22'),
  (1, 1, '2011-09-27 11:17:32'),
  (2, 2, '2011-09-27 11:34:13'),
  (3, 3, '2011-09-27 11:01:21'),
  (3, 3, '2011-09-27 13:36:28'),
  (2, 2, '2011-09-27 13:55:39'),
  (4, 4, '2011-09-27 14:25:07');

SELECT
  empid, projectnumber, MIN(clocktime) startdate, TIMEDIFF(MAX(clocktime), MIN(clocktime)) workhours
FROM
  table_proj
GROUP BY
  empid, projectnumber
HAVING
  COUNT(*) = 2;

+-------+---------------+---------------------+-----------+
| empid | projectnumber | startdate           | workhours |
+-------+---------------+---------------------+-----------+
|     1 |             1 | 2011-09-27 10:02:22 | 01:15:10  |
|     2 |             2 | 2011-09-27 11:34:13 | 02:21:26  |
|     3 |             3 | 2011-09-27 11:01:21 | 02:35:07  |
+-------+---------------+---------------------+-----------+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM