简体   繁体   中英

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

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.

Anyways, if you just put the table structure along with your requirement, I may be able to give you an exact query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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