简体   繁体   English

在sql中查找开发人员的平均年龄

[英]Find Average Age Of Developers in sql

I have the following tables in sql :我在 sql 中有以下表:

在此处输入图片说明

I want to find average age of Developers .我想找到 Developers 的平均年龄。 I also want to find the numbers of task for each priority of a task .我还想找到任务的每个优先级的任务数。 How can I do that ?我怎样才能做到这一点 ?

To find the average age of the developers assigned to all the tasks you need to run this query -要查找分配给您运行此查询所需的所有任务的开发人员的平均年龄 -

select AVG(e.Age) as age from `Employee` e join `Task_Assignment` ta on ta.Developer_ID = e.Employee_ID;

To find the number of tasks for each priority you need to run this query -要查找每个优先级的任务数,您需要运行此查询 -

select COUNT(t.TASK_ID) from `Task` t join `Task_Priority` tp on t.Task_ID = tp.Task_ID GROUP_BY tp.Priority_ID;

Hope this helps :)希望这可以帮助 :)

select sum(age)/count(*) as avg_age from (
select distinct developer, age from (
select * from Employee emp inner join Task_Assignment task_assign 
on emp.emp_id = task_assign.developer
) as a ) as b

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

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