简体   繁体   English

SQL 帮助? ROUND 和 AVG 函数?

[英]SQL Help? ROUND and AVG function?

SELECT ROUND(AVG(ANNUAL_SALARY),0)

I know that one I stated was incorrect.我知道我说的那个是不正确的。 Can someone correct it for me?有人可以为我纠正吗?

I am assuming that the table name is SalaryHistory我假设表名是 SalaryHistory

So the query will be所以查询将是

SELECT ROUND(AVG([ANNUAL_SALARY]), 0)
FROM SalaryHistory

This will give you average salary of all the employees, but if you want to get avg salary of each employee you need to write down the query something like this.这将为您提供所有员工的平均工资,但是如果您想获得每个员工的平均工资,您需要写下这样的查询。

SELECT ROUND(AVG([ANNUAL_SALARY]), 0), EmployeeID
FROM SalaryHistory
GROUP BY EmployeeID

You may join this EmployeeID with the Employee Table to get the Employee Name in the result set instead of getting EmployeeID only.您可以将此 EmployeeID 与 Employee 表连接起来以获取结果集中的 Employee Name,而不是仅获取 EmployeeID。

Anyways, if you just put the table structure along with your requirement, I may be able to give you an exact query.不管怎样,如果你只是把表结构和你的要求放在一起,我也许可以给你一个确切的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM