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
 dividing up result set into 4 groups

Author  Topic 

phaze
Starting Member

42 Posts

Posted - 2007-02-01 : 16:36:09
Hello,

I am trying to take my result set and dividing up the results into 4 equal
groups

I have included my code and a partial result set.
All of your input and help is appreciated as I am new at this


select accounts.id, sum(trans.amount) as 'income'
from jom.dbo.accounts
join jom.dbo.trans
on trans.accounts_id = accounts.id
where trans.amount > 0
group by accounts.id


id income
47109 8.00
47110 8.00
47111 12.00
47112 16.00
47125 16.00
47126 10.00
47127 8.00
47128 16.00
47129 42.99
47142 139.00
47143 8.00
47144 52.00
47145 5.00
47159 625.94
47160 75.00
47161 8.00
47162 8.00
47176 25.00
47177 20.00
47178 16.00
47179 28.00
47192 74.94
47193 248.00
47194 176.00
47195 39.99
47196 16.00
47209 16.00
47210 46.00
47211 177.00
47212 8.00
47226 44.00
47227 178.99
47228 24.97
47229 27.00
47242 16.00
47243 24.00
47244 8.00
47245 49.00
47246 70.00
47259 19.95
47260 10.00
47261 22.00
47262 40.00
47276 8.00
47277 68.00
47278 8.00
47279 8.00
47293 16.00
47294 56.00
47295 10.00
47296 63.00
47309 34.00
47311 26.00
47312 18.00
47326 24.00
47327 16.00
47328 215.00
47329 8.00
47343 19.95
47344 19.95
47345 19.95
47346 42.00
47359 62.00
47360 16.00
47361 75.00
47362 40.00
47363 8.00
47376 19.95
47377 19.95
47378 24.00
47379 13.00
47393 8.00
47394 98.95
47395 63.95
47396 25.95
47410 21.00
47411 47.00
47412 229.00
47413 8.00
47426 18.00
47427 8.00
47428 60.00
47429 44.95
47443 93.00
47444 20.00
47445 10.00
47446 18.00
47460 28.00
47461 16.00
47462 32.00
47463 48.00
47476 22.00
47477 110.00
47478 16.00
47479 36.00
47480 8.00
47493 98.95
47494 60.00
47495 24.00
47496 98.00

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-01 : 17:16:55
What is "4 equal groups"?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-01 : 19:56:09
what happen when the results is not divisible by 4 ?


KH

Go to Top of Page
   

- Advertisement -