jeudi 8 juin 2017

How to randomly select a certain percent of rows from a certain category in Access but with a condition to the total amount?

I have a table with, let's say, boys and girls. I want to randomly select 30% present of girls but at the same time this selection should be more than 10% of the total amounts of students ( sum of boys and girls), so if I select 30% of girls and it is less than 10% of sum, I select (for example) 40%, to overcome 10% ( not to a certain value, just 10%-10,1)%. For 30% selection I use

SELECT TOP 30 PERCENT from Students ORDER BY rnd(ID) Where StudentType=girl

How should I place additional condition and how to make this query change selection if 10% wasn't hit?




Aucun commentaire:

Enregistrer un commentaire