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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping?

Status
Not open for further replies.

RupertHaynes

Programmer
Aug 23, 2001
3
GB
Say I have an Id field which has values from 1-50, and another field called value which is an integer. How could I get the average of the value field from 1-10,10-20,20-30 etc.??
 

Try this.

Select
cast((RecID+9)/10. As Int) as RangeID,
avg(RandID) As TotValue
From dbo.AddressesAndPhones
Group By cast((RecID+9)/10. As Int)
Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
I have different sulution, but i dont't know if this is usefull for you:

select distinct (select avg(value) from tableA where id >= 1 and id <=10) as values_1_10,
(select avg(value) from tableA where id >=11 and id <=20 ) as values_11_20,
(select avg(value) from tableA where id >=21 and id <=30) as values_21_30
from tableA

result:

values_1_10 | values 11_20 | values 21_30
-----------------------------------------------
45 | 56 | 67

bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top