如何列出百分比大于某个数字的所有员工, 百分比根据最高工资计算。
示例:
如果最高工资为100且员工工资为50则为百分比 应该显示50。
这是我试过的:
select (salary/Max(salary)*100) as percentage from test.employeetable
where percentage > 75;
我得到的错误是:
'where子句
中的未知列'百分比'
答案 0 :(得分:2)
尝试类似的东西;
select * from (
select (salary / (select max(salary) from test.employeetable) * 100) as percentage from test.employeetable) Records
where percentage > 75;
答案 1 :(得分:1)
首先获取变量中的最大值,然后选择相关结果
select @max := max(salary) from test.employeetable;
select (salary/@max*100) as pc from test.employeetable having pc > 75;
请注意having
而不是where
。
您也可以显示相关薪水(等等)
select @max := max(salary) from test.employeetable;
select salary,(salary/@max*100) as pc from test.employeetable having pc > 75;
不使用变量
select (salary/m.mx*100) as pc from test.employeetable,
(select max(salary) as mx from test.employeetable) as m
having pc > 75;
答案 2 :(得分:0)
Select (salary/Max(salary)*100) as percentage
from test.employeetable
where (salary/Max(salary)*100) > 75;
在MySql中你不能在where子句
中使用“as”答案 3 :(得分:-1)
使用子查询
SELECT *
FROM (
SELECT (salary / MAX(salary) * 100) AS percentage
FROM test.employeetable
) x
WHERE percentage > 75