Mysql计算子查询

标签 mysql

我正在尝试为员工编写子查询。问题是:

列出所有工资高于平均工资的员工,并显示他们的工资高于平均工资的多少。

我有第一部分,但我似乎无法弄清楚如何计算 AVG 薪水和薪水之间的差异。

到此为止

Select name from staff where salary >=(select AVG(salary) from staff) 

如何添加差异部分?

编辑:表列为staffNo, name, position, salary, branchNo

最佳答案

我不确定这是达到预期结果的正确方法

Select name,Salary-(select AVG(salary) from staff)t AS Diff 
from staff 
where salary >=(select AVG(salary) from staff)

关于Mysql计算子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40490490/

相关文章:

php - 调用 codeigniter 中数组的成员函数 result()

php - 无法在使用 php 脚本加密的 mysql 中解密

mysql - Laravel 许多模型作为 Publisher 与枢纽的多态关系?

java - Android 网络服务 PHP MYSQL

c# - 异步使用 MySQL 数据库

mysql - 从一组相似的行中选择每分钟(日期)?

mysql - LEFT JOIN 创建多行、GROUP BY 或 DISTINCT

mysql - 将多行转换为列

python - 类型错误:无法将 'QRadioButton' 对象隐式转换为 str

MySQL数据目录空间问题