Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle AVG

Status
Not open for further replies.

Ringers

Technical User
Feb 26, 2004
180
AU
I have two columns SI_NUM and SI_MINUTES from the same table and I need to either get average of them by something like avg(si_num,si_minute), avg(column[si_num],column[si_minute]) or even just do a mathematical calculation of division between the two columns. But I don't know how to do this can anyone help me out, here is what I have tried so far.

SELECT CD_CODE,SU_CODE,SU_FNAME,SU_LNAME,SI_NUM,SI_MINUTE,
AVG(SI_NUM-SI_MINUTE) AVG
FROM FCDOPER,FSURGN,FSITEMS
WHERE CD_SEQU = SI_CD_SEQU and SU_SEQU = SI_SU_SEQU and CD_CODE = '56001'

Thanks
 
A couple of things:
First, it would be better to use something besides a reserved word or function name as a column alias. Secondly, since AVG is an aggregate function, you need to use a GROUP BY clause:
Code:
SELECT CD_CODE,SU_CODE,SU_FNAME,SU_LNAME,SI_NUM,SI_MINUTE,
       AVG(SI_NUM-SI_MINUTE) AVERAGE
FROM FCDOPER,FSURGN,FSITEMS
WHERE CD_SEQU = SI_CD_SEQU and SU_SEQU = SI_SU_SEQU and CD_CODE = '56001'
GROUP BY CD_CODE,SU_CODE,SU_FNAME,SU_LNAME,SI_NUM,SI_MINUTE;
Please give this a try and let us know if you're any closer to where you want to be.
 
What is SI_NUM exactly ? Why are you subtracting SI_MINUTE from SI_NUM when you say you need to divide them ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top