Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Grouping data for more efficient data selection Expand / Collapse
Posted Monday, November 4, 2013 1:09 PM


Group: General Forum Members
Last Login: Monday, December 8, 2014 9:37 AM
Points: 10, Visits: 75
I have a table containing 50000 records. The fields are, Phase, KVA, Amt and Group. To begin with, Group = 0 for all records. I have an input variable #Grps, telling me how many final groups the user wants. I am to determine the groups by Phase, KVA, and AMT in that order. For instance, All records with Phase = 1, KVA = 25 and AMT <= xxx would go into Group = 1, All records with Phase = 1, KVA = 25, Amt > xxx and Amt <= yyy would go into Group = 2, etc. until the maximum amt has been assigned to a group for this Phase and KVA. Then we would go to Phase 1, KVA = 50, and do it all over again. I know there's a formula for this, but I've been out of school a long time, and don't remember enough to find it on the internet. Can anyone reading this tell me what the formula is, or give me an efficient query to accomplish my goal?

The amount ranges are determined by the number of records (#Recs) in that grouping (Phase = 1, KVA = 25) divided by the total number of records(#TotRecs) times the #Grps, which gives us the number of groups allotted to this grouping (#SubGrps), so the number of records in each group within that grouping would be #Recs/#SubGrps or xxx in my example above. yyy would then be twice that amount.

This will require some tweaking, but if I can get this far, I can handle the rest.

Thanks guys

Post #1511267
Posted Monday, November 4, 2013 1:17 PM



Group: General Forum Members
Last Login: Today @ 7:51 AM
Points: 2,927, Visits: 29,602
some scripts to define table along with example data and expected output from example data will help considerably please.

you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Post #1511270
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse