php - Mysql percent based query -


is kind of mysql query possible?

  select power      ".$table."    category in ('convertible')       , type = bwm40%       , type = audi60%  order rand() 

would go this: cars, select power of ones convertible, 40% of selection bmw's , other 60% audi's.

can done mysql?

can't seem make work ideea bellow, gives me error, here how tried it:

    $result = mysql_query(" select power, torque ".$table."  category in ('convertible')  order (case type when 'bmw' 0.4 when 'audi' 0.6) * rand() desc  limit ".$offset.", ".$rowsperpage.""); 

you try adjusting randomness using case:

select power table category in ('convertible')   , type in ('bwm', 'audi') order (case type when 'bwm' wbwm when 'audi' waudi) * rand() desc 

where wbmw , waudi weighting factors. you'd add limit clause chop off results @ desired size. won't guarantee desired proportions might enough purposes.

you'd want play weighting factors (wbmw , waudi above) bit results want. weighting factors depend on frequencies of bwm , audi in database 0.2 , 0.8, example, might work better. chris notes in comments, 0.4 , 0.6 work if have 50/50 split between bmw , audi. putting weights in separate table make approach easier maintain , sql prettier.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -