Jump to content

Doing math in a query


shamoon

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.