Solved

# SQL Question - Splitting populations

Posted on 2004-11-04
268 Views
I have 2 separate populations in which I need to split each population randomly (50-50) and take the 50% from each population and combine them into a temp table.

Example:

Population A:
1000 people

Population B:
2000 people

Need to spilt Population A 50-50(randomly) and take 50%(500 people) and insert them in Temp Table C.  Then take 50% from Population B(again this would be randomly split at 50-50) and insert that into Temp Table C as well.  So Temp Table C would have a total population of 1500...

Any ideas on this?

Fiqbal
0
Question by:fiqbal

LVL 1

Accepted Solution

Here is the start to your solution, this is not really random - but randomness depends on how the data was entered in the first place:

DECLARE @TABLE_A_COUNT int
DECLARE @TABLE_B_COUNT int

SET @TABLE_A_COUNT = COUNT(*)/2 FROM TABLE_A
SET @TABLE_B_COUNT = COUNT(*)/2 FROM TABLE_B

SELECT TOP @TABLE_A_COUNT Field1 FROM TABLE_A

UNION

SELECT TOP @TABLE_B_COUNT Field1 FROM TABLE_A
0

LVL 15

Assisted Solution

Hi,

I'd suggest this as solution:

select top 50 percent * into tempTable from YourTable1
union
select top 50 percent * from YourTable2
select * from tempTable

Best regards,
Raisor
0

## Featured Post

### Suggested Solutions

Help with my python script 6 135
has77  challenge 9 56
tenRun challenge 28 67
countClumps  challenge 10 66
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…