General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 11th, 2012, 06:31 PM
complete complete is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 100 complete User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 49 m 8 sec
Reputation Power: 12
How do you use AVG() in sql to manage grouped output?

How do you use AVG() 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:



City Salary

Seattle 20000
Redmond 30000



Select City, AVG(Salary) from Employee where ... I don't know the rest

Where city == city or something like that?

Reply With Quote
  #2  
Old August 11th, 2012, 08:08 PM
bitsmed bitsmed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 11 bitsmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 53 sec
Reputation Power: 0
Hi,

In this particular case, you don't need a where clause.
You do need a group by clause though. Like this:
Code:
select city
      ,avg(salary) as avgsalary
  from employee
 group by city

If you want to include a where clause, write it before the group clause.

Have a look here

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > How do you use AVG() in sql to manage grouped output?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap