[英]Calculate Number of worked_days in Given month from Deployment data (Mysql/PHP)
I am working on Payroll System where an employee can be deployed on projects from any_date to any_date . 我正在使用薪资系统,可以在从any_date到any_date的项目中部署员工。 Sample MySQL table below 下面的示例MySQL表
id empid project_id start_date end_date
1 1 2 2016-11-05 15:10:22 2016-12-11 15:11:21
2 1 3 2016-12-13 15:26:10 2016-12-20 15:29:40
3 1 2 2016-12-23 15:31:46 2017-01-18 15:32:35
Now, if I want to calculate the number of days in given month worked on all projects, I am using Eloquent which translates to below query(I verified in DB::getQueryLog())
: 现在,如果我想计算给定月份在所有项目上工作的天数,我正在使用Eloquent,它转换为以下查询(我在DB::getQueryLog())
进行了验证DB::getQueryLog())
:
SELECT
*
FROM
payroll_project_tracks
WHERE
empid = 1
AND '2016-12-01 00:00:00' BETWEEN start_date AND end_date
AND '2016-12-31 23:59:59' BETWEEN start_date AND end_date
After getting the rows that have deployments of given month (month = Dec 2016 here), I want to calculate Number of Days worked on all projects in a given month. 获得具有给定月份部署的行(此处的月= 2016年12月)后,我要计算给定月份在所有项目上工作的天数。
I am getting no results with the above query. 上面的查询没有任何结果。 Can anyone correct me or let me know if there is some better way of doing this. 任何人都可以纠正我或让我知道是否有更好的方法可以做到这一点。
I think that the query should be: 我认为查询应该是:
SELECT *
FROM payroll_project_tracks
WHERE
empid = 1 AND
start_date <= '2016-12-31 23:59:59' AND
end_date >= '2016-12-01 00:00:00'
This query will return the 3 rows you provided, but will cut out the following: 该查询将返回您提供的3行,但将切出以下内容:
4 1 2 2017-01-01 15:31:46 2017-01-18 15:32:35
is this ok? 这个可以吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.