StrangerDanger
asked on
SQL Query - Ranking / Distribution
Hi,
SQL Server 2008 R2. I have a table with 3 relevant columns:
[FileName], [FileSize], [Group]
I'd like break up the recordset up into groups based on the even distribution of [FileSize];
If I decided to break the recordset into 5 groups I would set [Group] to either '1','2','3','4' or '5' and I would expect the SUM([FileSize]) for each group to be similar.
I can think of some round-about ways of accomplishing this but want to know if there is an elegant way to do so.
Thanks
SQL Server 2008 R2. I have a table with 3 relevant columns:
[FileName], [FileSize], [Group]
I'd like break up the recordset up into groups based on the even distribution of [FileSize];
If I decided to break the recordset into 5 groups I would set [Group] to either '1','2','3','4' or '5' and I would expect the SUM([FileSize]) for each group to be similar.
I can think of some round-about ways of accomplishing this but want to know if there is an elegant way to do so.
Thanks
can you post sample data and the output you are looking for?
ASKER
Sure... to re-iterate... I essentially I want to assign a group number to each row. When you sum the filesizes for each group, I'd like the totals to be relatively similar.
EXAMPLE INPUT:
[FileName],[FileSize],[Gro up]
mypicture.jpg, 200, NULL
mypicture2.jpg, 300, NULL
mydoc.doc,500, NULL
myexcelsheet.xls, 1000, NULL
mytextfile.txt,600, NULL
myslide.ppt,400, NULL
myaudio.mp3, 1100, NULL
myfile.txt, 100, NULL
mysite.html, 400, NULL
mypicture3, 550, NULL
EXAMPLE OUTPUT:
[FileName],[FileSize],[Gro up]
mypicture.jpg, 200, 1
mypicture2.jpg, 300,1
mydoc.doc,500,1
myexcelsheet.xls, 1000, 2
mytextfile.txt,600,3
myslide.ppt,400,3
myaudio.mp3, 1100,4
myfile.txt, 100, 5
mysite.html, 400, 5
mypicture3, 550, 5
Example aggregate:
[Group], [SumOfFileSize]
1, 1000
2, 1000
3, 1000
4, 1100
5, 950
EXAMPLE INPUT:
[FileName],[FileSize],[Gro
mypicture.jpg, 200, NULL
mypicture2.jpg, 300, NULL
mydoc.doc,500, NULL
myexcelsheet.xls, 1000, NULL
mytextfile.txt,600, NULL
myslide.ppt,400, NULL
myaudio.mp3, 1100, NULL
myfile.txt, 100, NULL
mysite.html, 400, NULL
mypicture3, 550, NULL
EXAMPLE OUTPUT:
[FileName],[FileSize],[Gro
mypicture.jpg, 200, 1
mypicture2.jpg, 300,1
mydoc.doc,500,1
myexcelsheet.xls, 1000, 2
mytextfile.txt,600,3
myslide.ppt,400,3
myaudio.mp3, 1100,4
myfile.txt, 100, 5
mysite.html, 400, 5
mypicture3, 550, 5
Example aggregate:
[Group], [SumOfFileSize]
1, 1000
2, 1000
3, 1000
4, 1100
5, 950
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@appari - This helped. Thanks mate.