?
Solved

SQL Question - Splitting populations

Posted on 2004-11-04
5
Medium Priority
?
313 Views
Last Modified: 2010-04-17
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
Comment
Question by:fiqbal
2 Comments
 
LVL 1

Accepted Solution

by:
ccarns earned 600 total points
ID: 12498770
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

by:Ralf Klatt
Ralf Klatt earned 600 total points
ID: 12500593
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Make the most of your online learning experience.
Six Sigma Control Plans
Introduction to Processes

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question