Jump to content

Recommended Posts

Hello all,

I have a query

 

SELCT b.title, IF( b.total_rentals > 0, b.copies_owned / b.total_rentals, 100) AS usage_ratio FROM books b,  WHERE b.status = 1 ORDER BY usage_ratio DESC

 

Is there a lot of overhead by doing my query like that?  I mean, including the calculation like that?

 

Thanks,

Shamoon

 

Link to comment
https://forums.phpfreaks.com/topic/75408-doing-math-in-a-query/
Share on other sites

If a query is slow because the table is large you can often speed it up by adding an index. In the case of a calculated value you can't do that.

 

However, as you need the results in that order it's something you'll have to live with. If you only have a few thousand records I wouldn't worry.

 

Try timing it with and without the ORDER BY to assess the impact.

Link to comment
https://forums.phpfreaks.com/topic/75408-doing-math-in-a-query/#findComment-381468
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.