-1

我有一个mysql表存储员工的表现,其中包括四个因素:

http://sqlfiddle.com/#!2/84375/1

现在我想按不同的比例对员工进行排名。

所有因素都是“越高越好”。

factor2 可以是负数。

他们的比例是:-

因素1:45%

因素2:25%

因素3:15%

因素4:15%

我不知道该怎么做

但是如果只用 sql 是不可能的,

我的服务器端语言是 PHP。

4

2 回答 2

0

这是否按您的意愿工作?

SELECT *, (45*Factor1 + 25*Factor2 + 15*Factor3 + 15*Factor4)/100 as Performance FROM EmployeePerformance ORDER BY Performance DESC

编辑:阅读评论后,我相信这就是你想要的

select *,
  ( 45 * Factor1 / (select SUM(Factor1) from EmployeePerformance)
   + 30*Factor2/(select SUM(Factor2) from EmployeePerformance)
   + 15*Factor3/(select SUM(Factor3) from EmployeePerformance) 
   + 15*Factor4/(select SUM(Factor4) from EmployeePerformance)
  ) / 100 as Performance
FROM EmployeePerformance 
ORDER BY Performance DESC
于 2013-08-05T10:38:20.583 回答
0

你找这个?

SELECT * , (45*Factor1 + 25*Factor2 + 15*Factor3 + 15*Factor4)/100 as proportion 
FROM EmployeePerformance 
ORDER BY id

演示

于 2013-08-05T10:43:18.500 回答