[英]How to create SQL query
I have data(result / output) in a table like this: 我在这样的表中有数据(结果/输出):
Project code project name associates time efforts in days
1 Analytics amol,manisha,sayali,pooja (21+17+20+17)=57
I need to calculate the time efforts in days. 我需要以天为单位计算时间。 I have done it for February and I have added each persons days he has worked in that month.
我已经完成了2月的工作,并增加了他在该月工作的每个工作日。 I mean I have all days minus absentee of any day of all associates.
我的意思是,我的所有员工全天都缺勤。
So, I need to do this by SQL queries. 因此,我需要通过SQL查询来执行此操作。
I have one table which contains all the associates present with dates. 我有一张表,其中包含与日期一起显示的所有关联。
Like this: 像这样:
UID username date
So can any one give me a suggestion how I could do this? 那么有人可以给我一个建议,我该怎么做?
It will be a better design to have a separate table to store projectid, team member id and his/her efforts in days. 最好有一个单独的表来存储projectid,团队成员id及其在几天内的工作。 so that you can write a simple join query to achieve what you want.
这样您就可以编写一个简单的联接查询来实现所需的功能。
Here is what I would do. 这就是我要做的。 Change you tables so you have:
更改表格,以便:
projects 专案
project_code project_name
1 Analytics
users 使用者
UID username date
1 amol
2 manisha
3 sayali
projects_users projects_users
project_code uid effort
1 1 21
1 2 17
1 3 20
Now you can query the result you asked for like this: 现在,您可以像这样查询所需的结果:
SELECT
p.project_code,
p.project_name,
GROUP_CONCAT(DISTINCT u.username SEPARATOR ', ') AS associates,
SUM(pu.effort) effort
JOIN users AS u
JOIN projects_users AS pu
FROM projects p
GROUP BY project_code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.