Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

Topic: SQL*Plus and PL/SQL >> partition

Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property. You may review the entire Oracle Certification Program Candidate Agreement online Here.



  


 Title: partition
 mellow  Posted: Dec 12, 2007 05:24:48 AM

 Total Post: 1
 Joined: Dec, 2007






 Hi

Some one please expalin me how this query working ?

SELECT manager_id, last_name, hire_date, salary,
AVG(salary) OVER (PARTITION BY manager_id ORDER BY hire_date
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS c_mavg
FROM employees;

Thanks in advance,
Sathish

 Murtuja
Posted: Dec 12, 2007 07:15:15 AM  

 Total Post: 857
 Joined: Jan, 2006






 
Your query is example of Analytic Functions - Window Aggregate Functions

http://www.ss64.com/orasyntax/an_agg_window.html
http://www.orafaq.com/node/55
http://www.orafusion.com/art_anlytc.htm

 chinna
Posted: Dec 13, 2007 12:54:36 AM  

 Total Post: 28
 Joined: May, 2007






 
hi,
consider this case

SELECT MGR, ENAME, hiredate, sal,
AVG(sal) OVER (PARTITION BY MGR ORDER BY hiredate) AS c_mavg ,
AVG(sal) OVER (PARTITION BY MGR ORDER BY hiredate ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS c_mavgrows
FROM emp where mgr = 7698


EMPNO ENAME HIREDATE SAL c_mAVG c_mAVGROWS
7698 ALLEN 20-FEB-81 1600 1600 1425
7698 WARD 22-FEB-81 1250 1425(1425 IS THE AVG OF 1600 AND 1250) 1450 (AVG OF 1600,1250,1500 Since they mentioned 1 preceding and 1 folowing)
7698 TURNER 08-SEP-81 1500 1450(avg of 1600,1250,1500) 1333.33(avg of 1250,1500,1250)
similarly
7698 MARTIN 28-SEP-81 1250 1400 1233.33
7698 JAMES 03-DEC-81 950 1310 1100


thanks
chinna

 Time Zone: EDT

  




Forum Rules & Description


Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user




 








Get FREE Magazines

Top 10 Forum User

  Murtuja Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gopu Gopi333
  Gitesh Trivedi322
  Vinoth Kumar264
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software