Partitioning By Counts In Sql
This issue is related to question I asked here. I have a table that looks like this: Item Count 1 1 2 4 3 8 4 2 5 6 6 3 I need to group item
Solution 1:
Why isn't this a correct result?
Item Group Count
111224338442556613Or this?
Item Group Count
111224338442556663Seems to me that you're trying to solve the answer 'how to group the items as to minimize the number of groups and maximize the number of items in each group, w/o exceeding the limit 5'. Which sounds a lot like the Knapsack problem. Perhaps a you should read the Celko's SQL Stumper: The Class Scheduling Problem and the solutions proposed. Others have also approached this problem, eg. And now for a completely inappropriate use of SQL Server. Heads up: this is no a trivial problem by any means. Any naive algorithm will die a slow death attempting to solve it on a 1M rows table...
Post a Comment for "Partitioning By Counts In Sql"