Oracle

Moderators: None (Apply to moderate this forum)
Number of threads: 348
Number of posts: 673

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Query Optimization Posted by ss135r on 14 May 2011 at 6:15 AM
Hi,

I have table like

emp salary
--- -------
emp1 10000
emp2 10000
emp3 11000
emp4 13000
emp5 15000

I want avg salary in a separate column like

emp salary AvgSalary
--- ------- -----------
emp1 10000 11800.0000
emp2 10000 11800.0000
emp3 11000 11800.0000
emp4 13000 11800.0000
emp5 15000 11800.0000

I am getting the result using
SELECT emp, salary, (SELECT AVG( salary ) FROM empl ) 'average'
FROM empl 


Can I do it using only one select statement.

Thanks,
Shrawan


Report
Re: Query Optimization Posted by totha on 17 May 2011 at 12:25 AM
SELECT emp, salary, AVG(salary) OVER() "average salary" FROM empl;




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.