SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Grouping data for more efficient data selection


Grouping data for more efficient data selection

Author
Message
SqlBound
SqlBound
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 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

#
J Livingston SQL
J Livingston SQL
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12317 Visits: 37589
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search