Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

database - Sql query to perform Load check for an Employee

I have a table design like this ...

  • 1 Project--> Multiple products.
  • 1 Product--> Multiple environment.
  • 1 Employee--> Multiple activities.

Status can be = "new", "inprogress", "on hold", "closed"

    Activity table- ActID(PK), assignedtoID(FK), Env_ID(FK), Product_ID(FK), project_ID(FK), Status. 
    Product_table - Product_ID(PK), Product_name
    Project_Table- Project_ID(PK), Project_Name. 
    Environment_Table- Env_ID(PK), Env_Name. 
    Employee_Table- Employee_ID(PK), Name.
    Employee_Product_projectMapping_Table -Emp_ID(FK), Project_ID(FK), Product_ID(FK).
    Product_EnvMapping_Table - Product_ID(FK), Env_ID(FK). 

Load check query

First find out the total number of activities assigned to each employee in a particular project.

(A). then find the number of activities for that employee in that project where status = new or inprogress. (B). Divide A/B. Compute this A/B in percentage value.

So my final query table output will consist of

  • Name of employee
  • name of project
  • total assigned act(Count value)
  • Act having status new or in process(Count)
  • Load(the percentage value. )

Can anyone help me with the query and explain how I can achieve this result? Thanks.

So far i have tried this much ... getting the results of A and B but now i need to combine these two...

(A).

SELECT activity_table.assignid, activity_table.projid, Count(activity_table.actid) AS CountOfactid
FROM activity_table
GROUP BY activity_table.assignid, activity_table.projid;

(B).

SELECT activity_table.assignid, activity_table.projid, Count(activity_table.actid) AS CountOfactid
FROM activity_table where status in ('new','inprogress')
GROUP BY activity_table.assignid, activity_table.projid ;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is Upto 3rd result...not for 4th one.

select Employee_table.name,Project_table.Project_Name, Count(activity_table.actid) AS CountOfactid

from Activity table,Employee_Table,Project_Table,Employee_Product_projectMapping_Table

where Activity_Table.Product_Id=Project_Table.Product_Id

 and 

aage ka syntax yaad nai aa raha hai...

Employee_Product_projectMapping_Table aur  Employee_Table ko combine karke emp name through equating product id...

for the 4th one use nested query......

will try to solve this query asap.....:P

409008....


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...