Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

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

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, March 28, 2014 9:43 AM
Points: 10, Visits: 74
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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 7:05 AM
Points: 1,899, Visits: 18,923
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 !
__________________________________________________________________
Post #1511270
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse