Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

A complicated SQL grouping/selecting question

$
0
0

I am having a bit of a hard time with a script and wanted to reach out to my favorite group of smart people to help me solve it.

I have a script to pull a bunch of data in SQL. It is basically this:

Group Name | Account Number

Group 1 | 12345

Group 1 | 257809

Group 2 | 11111

etc...

I am tryign to write a script to pull a random sample of ten percent (rounded up) from the population. That, in itself, was a pain to figure otu because there is no OOtB way to round up in SQL. I figured it out though.

But now the new problem arises: I need to pull 10% of each group, not 10% of the whole population. So if I have 5 accounts in Group 1, 12 in Group 2, 3 In Group 3, 1 in Group 4, and 20 in Group 5, I need to pull 1 account each from groups 1, 3, and 4, and 2 accounts each from groups 2 and 5.

And I have no bloody clue how to do that!


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>