Random Picking By Percentage

S

sanjeev_xp

Please can anyone help?

I have a table (voter_details) with several fields that tracks voter_id,
voter_name, voter_address and voter_zone.

I want to create a query or macro that getting 20% of voter_id from each
voter_zone on random basis.


For example, if voter_zone 1 has 500 Voter_id I want to list 100 voter_id
If voter_zone 2 has 900 Voter_id I want to list 180
voter_id
And so on.

The Table looks like this table=voter_details
Total Records = 1200000-1250000
Total Voter_Zone = 500-600

Voter_id Voter_name Voter_address Voter_zone
C89126 Ram 190, Ara
Pat-20
DD5490 Lalan H.No 60, Gaya Bih-60
AZ1259 Sita B/B-10, Ara
Pat-20


Hope you can help.
Thanks
 
K

KARL DEWEY

Try these two queries --
Voter_Zone_Percent --
SELECT voter_details.Voter_zone, Count([Voter_zone])\5 AS 20_Percent
FROM voter_details
GROUP BY voter_details.Voter_zone;


SELECT Q.Voter_zone, Q.Voter_id, Q.Voter_name, Q.Voter_address, (SELECT
Count(*) FROM voter_details AS Q1
WHERE Q1.Voter_zone = Q.Voter_zone
AND Q1.Voter_id > Q.Voter_id)+1 AS Rank
FROM voter_details AS Q INNER JOIN Voter_Zone_Percent ON Q.Voter_zone =
Voter_Zone_Percent.Voter_zone
WHERE ((((SELECT Count(*) FROM voter_details AS Q1
WHERE Q1.Voter_zone = Q.Voter_zone
AND Q1.Voter_id > Q.Voter_id))<=[20_Percent]))
ORDER BY Q.Voter_zone;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top