多个SQL数据表中,一个查询的平均值结果如何于另一个表格做关联?

比如有一个HR的数据库,相关的表有两个:employeeperformanceemployee 表就是员工的所有信息比如有departmentperformance表的结构如下:

performanceRating performanceDescriptor
1 Low
2 Good
3 Excellent
4 Outsanding

performanceRatingperformance表中为 primary key,在employee表中为 foreign key

如果需要知道每个部门的平均 PerformanceRaing,并按从小到大的顺序排列,则为:

SELECT Avg(employee.PerformanceRating) AS [Average Performance Raing], employee.Department
FROM employee
GROUP BY employee.Department
ORDER BY Avg(employee.PerformanceRating);

输出结果为:

Average Performance Raing Department
3.14655172413793 Sales
3.15514018691589 Research & Development
3.21212121212121 Human Resources

但是这样计算出的部门平均 performanceRating 不为整数,但是如果也需要在平均值旁附上performance的描述,即把performace表中的描述也跟在后面,不是仅仅展现出数字而已,应该如何操作呢,应该不能直接 INNER JOIN performance表吧?

比如的输出结果为:

Department Average Performance Raing PerformanceDescriptor
Sales 3.14655172413793 应该为Excellent?
Research & Development 3.15514018691589 应该为Excellent?
Human Resources 3.21212121212121 应该为Excellent?
阅读 4.5k
1 个回答

可以取整再去关联

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进