How select a percent of population.

19 Views Asked by At

I have a cars process function Im trying to optimize, right now isn't fast enough to process all the data, so I want to reduce the % of input.

I cant filter using random rows, because cars send continuos data and I need track the changes for each car (how much each car move in time). So I choose filter based in car_id

Select a size below 50% is easy, I can use the remainder of division to filter some %:

WHERE car_id % 2 = 0  -- select 50% of rows
WHERE car_id % 3 = 0  --        33%
WHERE car_id % 4 = 0  --        25%

I can calculate 1/n to get the pecentage selected.

My function already can manage 50% very efficent so I want increase the flow of data. But not sure how measure the limit in the other direction.

Using excel and filling cell with 1 .. 100 I was able to know:

WHERE car_id % 2 = 0 
   OR car_id % 3 = 0  -- Select 66%

WHERE car_id % 2 = 0 
   OR car_id % 3 = 0
   OR car_id % 4 = 0  -- Also Select 66% (now I know need combine prime numbers)

WHERE car_id % 2 = 0 
   OR car_id % 3 = 0
   OR car_id % 5 = 0  -- Select 74%

But dont know what formula can give me that result.

And how can I calculate a combination allow me to select something specific like ~70%