Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 TSQL Question

Author  Topic 

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-01-29 : 16:15:50
Can some one help me writing a set based Solution .....

Symbol-----Price
MSFT--------23.00
MSFT--------24.00
MSFT--------26.00
MSFT--------28.00
MSFT--------29.00
MSFT--------23.00
MSFT--------33.00
MSFT--------44.00
MSFT--------43.00
MSFT--------23.00
MSFT--------23.00
MSFT--------23.00
MSFT--------23.00
MSFT--------23.00
MSFT--------24.00

Just want to average Price every 10 rows together , but not using the CURSOR.
Like

Rows 1 to 10 -----AveragePrice
Rows 11 to 20 --- AveragePrice.......etc

Thx
Venu






Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-01-29 : 16:49:13
Rows in a table have no inherent order, so what would be the way to know the first 10 rows, next 10 rows, and so on?





CODO ERGO SUM
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-29 : 17:04:53
One thing is that, u should have a criteria to select the rows.

Use the paging as per the link
http://weblogs.sqlteam.com/jeffs/archive/2003/12/22/672.aspx

u can retrieve the results that u want, by using the above recursively (not using a cursor)


Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-01-29 : 17:30:07
given an integer seq column to number the rows

select seq / 10, avg(Price)
from tbl
group by seq / 10



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-01-29 : 20:11:51
ummmmm, the order of rows in a databse has no meaning....do I hear an echo?


Why not post the DDL of the table



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -