August 11th, 2012, 07:56 PM
AVG() in small groups
How do you use the AVG api in sql to manage grouped output? For example:
Given a SQL Table “Employee”
Name Salary City
John Doe 15000 Seattle
Jane Doe 30000 Redmond
Tim Wayne 25000 Seattle
Write a SQL query that would return the average salary per city in the format shown below:
Select City, AVG(Salary) from Employee where ... I don't know the rest
Where city == city or something like that?
August 11th, 2012, 08:40 PM
i don't think you need a WHERE clause -- use the GROUP BY clause
August 12th, 2012, 01:23 AM
do you mean somethinglike this?
Do you mean something like this?
,avg(salary) as avgsalary
group by city
August 12th, 2012, 06:54 AM
what happened when you tested that?
Originally Posted by complete