try this:create table ejb(clientID int,ProductName varchar(10),size float,Date smalldatetime)insert into ejbselect 100,'bfc',48.38,'2010/01/02' union allselect 100,'bfc',49.65,'2010/01/03' union allselect 100,'bfc',50.77,'2010/01/04' union allselect 100,'bfc',51.12,'2010/01/05' union allselect 100,'bfc',35.12,'2010/01/06' union allselect 100,'bfc',36.87,'2010/01/07' union allselect 101,'bdd',2.06,'2010/01/07' union allselect 101,'bdd',1.36,'2010/01/06' --(8 row(s) affected)selectx.clientID,avg(DIFF) as avg_DIFFfrom(select -- e2.size-- ,e2.date-- ,e1.size-- ,e1.date DIFF=e2.size - e1.size ,e1.clientIDfrom ejb as e1join ejb as e2on e1.clientID = e2.clientid and e1.date = e2.date+1) as xgroup by x.clientIDorder by x.clientID