sql - How to include column in resultset without including it in group by clause or performing any aggregation on it? -


given list containing city, empname , salary, sorted city , empname, how output each empname , salary total salary per city?

here have got:

select empname, sum(salary) table group province;

but gives me error have not included empname in group clause and/or not performing aggregation on it. how can achieve desired results? help?

if, want, sum of salary in city each employee, have 2 options. first should work in database:

select empname, tcity.citysalary t join      (select city, sum(salary) citysalary       t       group city      ) tcity      on tcity.city = t.city 

the second way use window function. notably, doesn't work on mysql:

select emptname, sum(salary) on (partition city) t 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -