I have a doubt in SQL Server query
I have a table dbo.[Files]
with columns Id
, FileName
, FileSize(MB)
Id FileName FileSize(MB)
----------------------------
1 aa.gif 3
2 bb.gif 5
3 cc.gif 7
4 dd.gif 5
5 ee.gif 2
6 fff.gif 4
7 gg.gif 3
My requirement is, I have to group with maximum file size limit and give a group Number for a group having sum of filesize less than or equal to the maximum limit
Suppose maximum file size sum is 10
Example result:
Id FileName FileSize(MB) GroupNo
--------------------------------------
1 aa.gif 3 1
2 bb.gif 5 1
5 ee.gif 2 1
3 cc.gif 7 2
7 gg.gif 3 2
4 dd.gif 5 3
6 fff.gif 4 3
Sum of FileSize in a Group is 10
Final result required
GroupNo Ids
--------------
1 1,2,5
2 4,6
3 3,7
` tags, either!! – marc_s Jul 16 '15 at 12:32