Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:18:23+00:00 2026-05-23T12:18:23+00:00

Is this kind of mysql query possible? SELECT power FROM .$table. WHERE category IN

  • 0

Is this kind of mysql query possible?

  SELECT power 
    FROM ".$table."
   WHERE category IN ('convertible') 
     AND type = bwm40% 
     AND type = audi60% 
ORDER BY RAND()

Would go something like this: from all the cars, select the power of the ones that are convertible, but 40% of the selection would be bmw’s and the other 60% audi’s.

Can this be done with mysql?

Can’t seem to make it work with the ideea bellow, gives me an error, here is how I tried it:

    $result = mysql_query("
SELECT power, torque FROM ".$table." 
WHERE category IN ('convertible') 
ORDER BY (case type when 'bmw' then 0.4 when 'audi' then 0.6) * RAND() DESC 
LIMIT ".$offset.", ".$rowsperpage."");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:18:24+00:00Added an answer on May 23, 2026 at 12:18 pm

    You could try adjusting the randomness using a CASE:

    SELECT power
    FROM table
    WHERE category IN ('convertible')
      AND type IN ('bwm', 'audi')
    ORDER BY (case type when 'bwm' then Wbwm when 'audi' then Waudi) * RAND() DESC
    

    Where Wbmw and Waudi are weighting factors. Then you’d add a LIMIT clause to chop off the results at your desired size. That won’t guarantee your desired proportions but it might be good enough for your purposes.

    You’d want to play with the weighting factors (Wbmw and Waudi above) a bit to get the results you want. The weighting factors would depend on frequencies of bwm and audi in your database so 0.2 and 0.8, for example, might work better. As Chris notes in the comments, 0.4 and 0.6 would only work if you have a 50/50 split between BMW and Audi. Putting the weights in a separate table would make this approach easier to maintain and the SQL would be prettier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How could I make this kind of query e.g. in MySQL SELECT * FROM
Is it possible use a MySQL query to perform this kind of check? If
I have a mysql query like this SELECT id, dpost FROM uid1088_qposts UNION SELECT
I want to write this kind of a MySQL query. select image_path, replace(replace(replace(description,\'/images/\',image_path),\'<![CDATA[\',\'\'),\']]>\',\'\') description
The question I have is kind of simular to this one - MySQL select
I have this kind of mysql db (table name/fields) tbl_users : id, title, approved
I perform this kind of query in my Python code to conn = rdbms.connect(instance=_INSTANCE_NAME,
I want to write one mysql query to fetch all my table data and
I have the below query: SELECT ID FROM `Article` this_ WHERE (this_._Temporary_Flag = FALSE
Possible Duplicate: Issue with displaying SQL result in DataGridView I've kind of asked this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.