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

时间:2016-04-02 15:44:48

标签: sql

我在sql中有以下表格:

enter image description here

我想找到开发人员的平均年龄。我还想找到任务的每个优先级的任务数。我怎样才能做到这一点 ?

2 个答案:

答案 0 :(得分:0)

要查找分配给运行此查询所需的所有任务的开发人员的平均年龄 -

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

要查找运行此查询所需的每个优先级的任务数 -

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

希望这会有所帮助:)

答案 1 :(得分:0)

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